cpptest测试总结

项目继续,持续新增中……

  1. 桩函数设置

    (函参指针赋值)

    √:fun(*p)

    {

    for(int i = 0; i<6; i++)

    p[i] = 10;

    }

    ×:fun(*p)

    {

    for(int i = 0; i<6; i++)a[i] = 10;

    p = a;

    }

    调用次数

    static int i = 0;

    i++;

    if(1 == i)return 1;

    else if(2 == i)return 2;

    桩函数参数为void类型

    fun(void *p)

    {

    double * tt;

    tt = (double*)p;

    tt[0] = 1.0;

    }

     

  2. 用例设置

    cpptest倾向单元测试步骤

    1.打桩

    2.循环变量先设完

    3.数组初始化

    4.观察源代码中有无除0的情况

    c++调试

    #include<iostream>

    using namespace std;

    cout<<xx<<endl;

    system("pause");

    文件找不到路径

    #include<direct.h>

    fopen("down_level.out",r+);

    char buff[256];

    _getcwd(buff,256);

    文件打开失败

    1.不存在

    2.文件只读

    字符串拷贝隐患:在拷贝前应确认拷贝内容,包括中止符,否则将越界拷贝

    char ca_dir[128] = " ";

    for(int i = 0; i<128; i++) ca_dir[i] = "1";

    char s1[256] = " ";

    char s2[256] = " ";

    1.strcpy(s1,ca_dir); ——>s1 = ……烫

    2.strncpy(s1,ca_dir,128); ——>s1 = 1……1(128)

    同理:strcat……

    new失败:内存已满,申请内存过多……

    1.int A = new(std::nothrow)int[10];

    2.int B = new int[10];

    A中使new不抛出异常,返回NULL,且代码1比2运行快

    if(A! = NULL){……}

    new

    int **p = new int*[k];

    for(int i = 0; i<k; i++)

    delete []p[m];

    delete []p;

    【new——delete(对变量)】

    【new[]——delete[](对数组)】

    二级指针初始化

    int *p1 = NULL;

    int **p2 = &p1;

    ——————————————

    int a[2] = {1,2};

    int *p1 = &a;

    int **p2 = &p1;

    二级数组指针初始化

    int **p = new int*[10];

    for(int i = 0; i<10; i++)

    {

    p[i] = new int[10];

    }

    函数运用:指针不能直接等于字符串???

    √:fun(*p)

    {

    char k[] = "i am rich";

    strcpy(p,k);

    return p;

    }

    ×:fun(*p)

    {

    p = "i am rich";

    return p;

    }

     

    c = fun("*i am rich*");

    char fun(char* b);

    cout << b<<endl;

    ——>*i am rich*

    结构体整体赋值为0

    struct st_a;

    st_a a;

    memset(&a,0,sizeof(st_a));

    ——————————————

    st_a a = {0};

    逻辑条件

    ||:+?、-+

    &&:++、+-、-+

猜你喜欢

转载自www.cnblogs.com/yeyeye123/p/10645423.html