• 测试用例文档


    1.测试有关说明

    1.1测试名称与内容

    发布过程

    1.2测试用例

    • 【发布过程】:用户登录之后,进入“我的”个人主页,点击“发布”按钮,协调数据库操作,实现发布商品的功能。
        public class UploadItemActivity extends AppCompatActivity {
        public static final int TAKE_PHOTO = 1;
        public static final int CHOOSE_PHOTO = 2;
        private ImageView picture;
        private Uri imageUri;
        private  DatabaseHelper dbHelper;
        private Spinner sp;
        private ContentValues values=new ContentValues();
        final SQLiteDatabase db = dbHelper.getWritableDatabase();
        private void displayImage(String imagePath) {//同时把图片加载到数据库
            if (imagePath != null) {
                Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
                picture.setImageBitmap(bitmap);
                values.put("image",baos.toByteArray());
                db.insert("iteminfo",null,values);
            } else {
                Toast.makeText(this, "failed to get image", Toast.LENGTH_SHORT).show();
            }
        }
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.upload_item);
            picture = (ImageView) findViewById(R.id.item_photo);
            Button finish_upload = (Button) findViewById(R.id.finish);
            Button chooseFromAlbum = (Button) findViewById(R.id.choose_photo);
            Button takePhoto = (Button) findViewById(R.id.take_photo);
            String[] ctype = new String[]{"生活用品", "学习用品", "电子产品", "体育用品"};
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, ctype);  //创建一个数组适配器
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);     //设置下拉列表框的下拉选项样式
            Spinner spinner = (Spinner) super.findViewById(R.id.item_style);
            spinner.setAdapter(adapter);
            sp = (Spinner) findViewById(R.id.item_style);
            final String kind = (String) sp.getSelectedItem();
            finish_upload.setOnClickListener(new View.OnClickListener(){
                @RequiresApi(api = Build.VERSION_CODES.O)
                @Override
                public void onClick(View v){ //上传商品信息插入到数据库
                    EditText title=(EditText)findViewById(R.id.item_name);
                    EditText price=(EditText)findViewById(R.id.item_price);
                    EditText intro=(EditText)findViewById(R.id.item_introduction);
                    EditText contact=(EditText)findViewById(R.id.contact);
                    //在登录功能中给post_userid赋值 values.put("userId",post_userid);
                    values.put("title",title.getText().toString());
                    values.put("userId",post_userid);
                    values.put("kind", kind);
                    values.put("price",price.getText().toString());
                    values.put("contact",contact.getText().toString());
                    values.put("intro",intro.getText().toString());
                    //bmp.compress(Bitmap.CompressFormat.PNG, 100, os);
                   // cv.put("pic", os.toByteArray());
                    db.insert("iteminfo",null,values);
                    Toast.makeText(getApplicationContext(), "发布成功", Toast.LENGTH_SHORT).show();
                    MyItems.actionStart(UploadItemActivity.this);
                }
            });
    
    • 【查询过程】查询数据库中存储的物品信息,并显示
        public class MyItems extends AppCompatActivity {
        String TABLENAME = "iteminfo";
        byte[] imagedata;
        Bitmap imagebm; //图片类型必须是Bitmap
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.my_item);
            final DatabaseHelper dbtest = new DatabaseHelper(this);
            final Intent intent = getIntent();
            final SQLiteDatabase db = dbtest.getWritableDatabase();
            ImageView image = (ImageView)findViewById(R.id.item_photo);
            TextView title = (TextView) findViewById(R.id.item_name);
            TextView price = (TextView)findViewById(R.id.item_price);
            TextView intro = (TextView) findViewById(R.id.item_introduce);
            TextView contact = (TextView) findViewById(R.id.contact);
            Button button_return = (Button) findViewById(R.id.button_return);
            Cursor cursor = db.query(TABLENAME,null,"id=?",new String[]{intent.getStringExtra("id")},null,null,null,null); // 根据接收到的id进行数据库查询
            Log.i("商品的id是",intent.getStringExtra("id"));
            if (cursor.moveToFirst()){
                while (!cursor.isAfterLast()){
                    imagedata = cursor.getBlob(6);
                    imagebm = BitmapFactory.decodeByteArray(imagedata, 0, imagedata.length);
                    image.setImageBitmap(imagebm);//把图片从数据库加载到image
                    title.setText(cursor.getString(2));
                    intro.setText(cursor.getString(4));
                    price.setText(cursor.getString(5));
                    contact.setText(cursor.getString(7));
                    cursor.moveToNext();
                }
                cursor.close();
            }
            button_return.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    UploadItemActivity.actionStart(MyItems.this);
                }
                });
        }
        public static void actionStart(Context context){
            Intent intent = new Intent(context, MyItems.class);
            context.startActivity(intent);
        }
    }
    
  • 相关阅读:
    Python中的返回函数与闭包
    Python的高阶函数小结
    Python的生成器Generator小结
    Vim插件YCM的安装
    用Vundle管理Vim插件
    声卡(Sound Card)基本概念
    Linux中Source的用法
    js 的执行过程
    mongoose@4.5.2的eachAsync bug
    [mongodb] MMAP 和wiredTiger 的比较
  • 原文地址:https://www.cnblogs.com/2019engineering/p/12081174.html
Copyright © 2020-2023  润新知