Exemplo n.º 1
0
 void run_test( int casenum = -1 ) {
    if ( casenum != -1 ) {
       if ( run_test_case( casenum ) == -1 )
          cerr << "Illegal input! Test case " << casenum << " does not exist." << endl;
       return;
    }
    
    int correct = 0, total = 0;
    for ( int i=0;; ++i ) {
       int x = run_test_case(i);
       if ( x == -1 ) {
          if ( i >= 100 ) break;
          continue;
       }
       correct += x;
       ++total;
    }
    
    if ( total == 0 ) {
       cerr << "No test cases run." << endl;
    } else if ( correct < total ) {
       cerr << "Some cases FAILED (passed " << correct << " of " << total << ")." << endl;
    } else {
       cerr << "All " << total << " tests passed!" << endl;
    }
 }
Exemplo n.º 2
0
int test_run(unsigned int suite, unsigned int tcase)
{
    int i, j;

    if (suite == ALL_SUITES)
    {
        /* run all suites */
        for (i = 0; i < NO_SUITES; i++)
        {
            if (suite_name[i] != NULL)
                printf("\nSuite %d: %s\n", i, suite_name[i]);
            for (j = 0; j < NR_TESTS; j++)
                (void) run_test_case(i, j);
        }       
    }
    else
    {
        if (suite > NO_SUITES)
        {
            fprintf(stderr, "error: invalid suite (%d)\n", suite);
            return -1;
        }

        /* run specfic suite */
        if (tcase == ALL_TESTS)
        {
            printf("\nSuite %d: %s\n", suite, suite_name[suite]);
            /* run all cases */
            for (j = 0; j < NR_TESTS; j++)
                (void) run_test_case(suite, j);
        }
        else
        {
            if (tcase > NR_TESTS)
            {
                fprintf(stderr, "error: invalid test case (%d)\n", tcase);
                return -1;
            }

            printf("\nSuite %d: %s\n", suite, suite_name[suite]);
            /* run specific test case*/
            if (run_test_case(suite, tcase) == -1)
                return -1;
        }
    }

    /* Print result */
    printf("\n=====================================================================================\n\n");
    printf("   Test Result:\n");
    printf("      Total:  %u\n", test_total);
    printf("      Passed: %u\n", test_passed);
    printf("      Failed: %u\n", test_failed);

    if (test_failed == 0)
        return 0;
    else
        return -1;
}
Exemplo n.º 3
0
int main(int argc, char **argv) {

#if SILENT_LOGGING
    FILE* fp;
  if ((fp = fopen("logtest.conf", "a+")) == NULL) {
    perror("file: ");
    return -1;
  }
  JNXLOG_OUTPUT_REDIRECT_START(fp);

#endif
  if (argc == 2 && strcmp(argv[1], "--help") == 0) {
    print_usage();
    return 0;
  }

  if (argc > 2) { // sort argv[1] to argv[argc-1] alphabetically
    void *base = (void *)(argv + 1);
    qsort(base, argc - 1, sizeof(char *), compare_args);
  }

#ifdef TEST_DISABLE_IPV6
  JNXLOG(LDEBUG,"Running with disabled IPv6 tests");
#endif

  int i;
  if (argc > 1) {
    int next_tc = 1;
    for (i = 0; i < test_suite_size; i++) {
      int cf_res = strcmp(test_suite[i].test_case_name + 8, argv[next_tc]);

      if (cf_res == 0) {
        run_test_case(test_suite[i]);
        next_tc++;
      }
      else if (cf_res > 0)
        next_tc++;

      if (next_tc >= argc)
        break;
    }
  }
  else {
    for (i = 0; i < test_suite_size; i++)
      run_test_case(test_suite[i]);
  }
#ifdef SILENT_LOGGING
  JNXLOG_OUTPUT_REDIRECT_END()
  fclose(fp);
#endif
  printf("Returning 0 from tests\n");
  return 0;
}
Exemplo n.º 4
0
static bool read_and_run_test_case(const char* filename, const SkBitmap& bitmap,
                        SkCanvas* canvas) {
  SkString testdata;
  SkDebugf("Test case: %s\n", filename);
  // read_test_case will print a useful error message if it fails.
  if (!read_test_case(filename, &testdata))
    return false;
  run_test_case(testdata, bitmap, canvas);
  return true;
}
Exemplo n.º 5
0
enum pamtest_err _pamtest_conv(const char *service,
			       const char *user,
			       pam_conv_fn conv_fn,
			       void *conv_userdata,
			       struct pam_testcase test_cases[],
			       size_t num_test_cases)
{
	int rv;
	pam_handle_t *ph;
	struct pam_conv conv;
	size_t tcindex;
	struct pam_testcase *tc = NULL;
	bool call_pam_end = true;

	conv.conv = conv_fn;
	conv.appdata_ptr = conv_userdata;

	if (test_cases == NULL) {
		return PAMTEST_ERR_INTERNAL;
	}

	rv = pam_start(service, user, &conv, &ph);
	if (rv != PAM_SUCCESS) {
		return PAMTEST_ERR_START;
	}

	for (tcindex = 0; tcindex < num_test_cases; tcindex++) {
		tc = &test_cases[tcindex];

		rv = run_test_case(ph, tc);
		if (rv == PAMTEST_ERR_KEEPHANDLE) {
			call_pam_end = false;
			continue;
		} else if (rv != PAMTEST_ERR_OK) {
			return PAMTEST_ERR_INTERNAL;
		}

		if (tc->op_rv != tc->expected_rv) {
			break;
		}
	}

	if (call_pam_end == true && tc != NULL) {
		rv = pam_end(ph, tc->op_rv);
		if (rv != PAM_SUCCESS) {
			return PAMTEST_ERR_END;
		}
	}

	if (tcindex < num_test_cases) {
		return PAMTEST_ERR_CASE;
	}

	return PAMTEST_ERR_OK;
}
Exemplo n.º 6
0
TEST_F(ecdh_test, ecdh_test)
{
    int iRan=0;
    for (unsigned i = 0; i < test_cases.size(); ++i)
    {
        struct ecdh_test_case const& case_ = test_cases[i];

        ASSERT_TRUE(!case_.mode.empty());

        if (case_.mode == "P-224")
        {
            iRan++;
            run_test_case(case_,mintls_secp224r1);
        }
        else if (case_.mode == "P-256")
        {
            iRan++;
            run_test_case(case_, mintls_secp256r1);
        }
    }
}
Exemplo n.º 7
0
static void run_test_set(FILE *fp, int n_test_cases, int len_test_case, QS_func_t qs_func) {
  int v[len_test_case];
  
  for (int k = 0; k < n_test_cases; k++) {
    for(int i = 0; i < len_test_case; i++) {
      if (fscanf(fp, "%d", &v[i]) != 1) {
	fprintf(stderr, "Formato invalido");
	exit(1);
      }      
    }
    //print_arr(v, len_test_case);
    run_test_case(v, len_test_case, qs_func);
  }
}
int main() {
  int ret = 0;
  unsigned i;

  for (i = 0; i < sizeof(test_cases) / sizeof(struct test_case); i++) {
    if (!run_test_case(i, &test_cases[i])) {
      ret = 1;
    }
  }

  if (ret == 0) {
    printf("PASS\n");
  }

  return ret;
}
/******************************************************************************//**
 * @author Erik Hattervig
 *
 * @Description
 * A recursive file traversal that gets a root directory and traverses through
 * all sub-directories looking for .tst files. When a tst file is found the
 * function will call for it to be tested
 * 
 * @param[in] rootDir
 * @param[in,out] logFile - a filestream to the logFile so that is passed on
 * to the tester functions
 * @returns none
 *********************************************************************************/
void DirCrawl( std::string rootDir , std::ofstream &logFile , std::string exec , int &passed , int &tested )
{
	DIR* dir = opendir( rootDir.c_str() );	// Open the directory
	struct dirent* file;	// File entry structure from dirent.h
	std::string filename;	//used in finding if a file has the extention .tst

	// Read each file one at a time
	// Readdir returns next file in the directory, returns null if no other files exist
	while( ( file = readdir(dir)) != NULL )
	{
		//place file name into string filename for easier checking
		filename = file->d_name;

		// skip over the directories "." and ".."
		if ( filename != "." && filename != ".." )
		{
			// checks if the file is a subdirectory, 4 is the integer idetifyer
			// for the dirent struct on Lixux systems
			if ( (int)file->d_type == 4 )
			{
				//moves into the sub-directory
                DirCrawl( rootDir + filename + "/" , logFile , exec , passed , tested );
			}
			else
			{
				// checks if the file has a .tst in it. string find returns
				// string::npos if the substring cannot be found
				if ( filename.find( ".tst") != std::string::npos )
				{
					// pass the file onto the grader 
                    if (run_test_case( rootDir + '/' + filename , exec , logFile ) )
					{
						passed += 1;
					}
					tested += 1;

				}
			}
		}
	}

	closedir(dir);

	return;
}
Exemplo n.º 10
0
void CV_MLBaseTest::run( int start_from )
{
    int code = CvTS::OK;
    start_from = 0;
    for (int i = 0; i < test_case_count; i++)
    {
        int temp_code = run_test_case( i );
        if (temp_code == CvTS::OK)
            temp_code = validate_test_results( i );
        if (temp_code != CvTS::OK)
            code = temp_code;
    }
    if ( test_case_count <= 0)
    {
        ts->printf( CvTS::LOG, "validation file is not determined or not correct" );
        code = CvTS::FAIL_INVALID_TEST_DATA;
    }
    ts->set_failed_test_info( code );
}
Exemplo n.º 11
0
static int run_tests(void)
{
    unsigned int i = 0, ncases = ARRAY_SIZE(eme2_test_cases);
    int res, failed = 0;

    printk("eme2_test: Running tests...\n");
    for (i = 0; i < ncases; i++) {
        printk("eme2_test: Running testcase %u...\n", i);
        res = run_test_case(&eme2_test_cases[i], i);
        if (res < 0) {
            return -EINVAL;
        }
        failed += res;
    }
    if (failed) {
        printk("eme2_test: FAIL: %i tests failed!\n", failed);
    } else {
        printk("eme2_test: OK!\n");
    }
    return 0;
}
Exemplo n.º 12
0
int
main(int argc, char **argv)
{
    FILE *f;
    const EVP_AEAD *aead = NULL;
    unsigned int line_no = 0, num_tests = 0, j;

    unsigned char bufs[NUM_TYPES][BUF_MAX];
    unsigned int lengths[NUM_TYPES];

    if (argc != 2) {
        fprintf(stderr, "%s <test file.txt>\n", argv[0]);
        return 1;
    }

    f = fopen(argv[1], "r");
    if (f == NULL) {
        perror("failed to open input");
        return 1;
    }

    for (j = 0; j < NUM_TYPES; j++)
        lengths[j] = 0;

    for (;;) {
        char line[4096];
        unsigned int i, type_len = 0;

        unsigned char *buf = NULL;
        unsigned int *buf_len = NULL;

        if (!fgets(line, sizeof(line), f))
            break;

        line_no++;
        if (line[0] == '#')
            continue;

        if (line[0] == '\n' || line[0] == 0) {
            /* Run a test, if possible. */
            char any_values_set = 0;
            for (j = 0; j < NUM_TYPES; j++) {
                if (lengths[j] != 0) {
                    any_values_set = 1;
                    break;
                }
            }

            if (!any_values_set)
                continue;

            switch (aead_from_name(&aead, bufs[AEAD])) {
            case 0:
                fprintf(stderr, "Skipping test...\n");
                continue;
            case -1:
                fprintf(stderr, "Aborting...\n");
                return 4;
            }

            if (!run_test_case(aead, bufs, lengths, line_no))
                return 4;

            for (j = 0; j < NUM_TYPES; j++)
                lengths[j] = 0;

            num_tests++;
            continue;
        }

        /* Each line looks like:
         *   TYPE: 0123abc
         * Where "TYPE" is the type of the data on the line,
         * e.g. "KEY". */
        for (i = 0; line[i] != 0 && line[i] != '\n'; i++) {
            if (line[i] == ':') {
                type_len = i;
                break;
            }
        }
        i++;

        if (type_len == 0) {
            fprintf(stderr, "Parse error on line %u\n", line_no);
            return 3;
        }

        /* After the colon, there's optional whitespace. */
        for (; line[i] != 0 && line[i] != '\n'; i++) {
            if (line[i] != ' ' && line[i] != '\t')
                break;
        }

        line[type_len] = 0;
        for (j = 0; j < NUM_TYPES; j++) {
            if (strcmp(line, NAMES[j]) != 0)
                continue;
            if (lengths[j] != 0) {
                fprintf(stderr, "Duplicate value on line %u\n",
                        line_no);
                return 3;
            }
            buf = bufs[j];
            buf_len = &lengths[j];
            break;
        }

        if (buf == NULL) {
            fprintf(stderr, "Unknown line type on line %u\n",
                    line_no);
            return 3;
        }

        if (j == AEAD) {
            *buf_len = strlcpy(buf, line + i, BUF_MAX);
            for (j = 0; j < BUF_MAX; j++) {
                if (buf[j] == '\n')
                    buf[j] = '\0';
            }
            continue;
        }

        for (j = 0; line[i] != 0 && line[i] != '\n'; i++) {
            unsigned char v, v2;
            v = hex_digit(line[i++]);
            if (line[i] == 0 || line[i] == '\n') {
                fprintf(stderr, "Odd-length hex data on "
                        "line %u\n", line_no);
                return 3;
            }
            v2 = hex_digit(line[i]);
            if (v > 15 || v2 > 15) {
                fprintf(stderr, "Invalid hex char on line %u\n",
                        line_no);
                return 3;
            }
            v <<= 4;
            v |= v2;

            if (j == BUF_MAX) {
                fprintf(stderr, "Too much hex data on line %u "
                        "(max is %u bytes)\n",
                        line_no, (unsigned) BUF_MAX);
                return 3;
            }
            buf[j++] = v;
            *buf_len = *buf_len + 1;
        }
    }

    printf("Completed %u test cases\n", num_tests);
    printf("PASS\n");
    fclose(f);

    return 0;
}
Exemplo n.º 13
0
ERROR_CODE run_speed_tests() {
    ERROR_CODE return_value = run_test_case(exec_speed_tests, "speed_tests");
    RAISE_AGAIN(return_value);
}
Exemplo n.º 14
0
void CV_UndistortPointsBadArgTest::run(int)
{
    //RNG& rng = ts->get_rng();
    int errcount = 0;
    useCPlus = false;
//initializing
    img_size.width = 800;
    img_size.height = 600;
    double cam[9] = {150.f, 0.f, img_size.width/2.f, 0, 300.f, img_size.height/2.f, 0.f, 0.f, 1.f};
    double dist[4] = {0.01,0.02,0.001,0.0005};
    double s_points[N_POINTS2] = {img_size.width/4,img_size.height/4};
    double d_points[N_POINTS2];
    double p[9] = {155.f, 0.f, img_size.width/2.f+img_size.width/50.f, 0, 310.f, img_size.height/2.f+img_size.height/50.f, 0.f, 0.f, 1.f};
    double r[9] = {1,0,0,0,1,0,0,0,1};

    CvMat _camera_mat_orig = cvMat(3,3,CV_64F,cam);
    CvMat _distortion_coeffs_orig = cvMat(1,4,CV_64F,dist);
    CvMat _P_orig = cvMat(3,3,CV_64F,p);
    CvMat _R_orig = cvMat(3,3,CV_64F,r);
    CvMat _src_points_orig = cvMat(1,4,CV_64FC2,s_points);
    CvMat _dst_points_orig = cvMat(1,4,CV_64FC2,d_points);

    _camera_mat = &_camera_mat_orig;
    _distortion_coeffs = &_distortion_coeffs_orig;
    matP = &_P_orig;
    matR = &_R_orig;
    _src_points = &_src_points_orig;
    _dst_points = &_dst_points_orig;

//tests
    CvMat* temp1;
    CvMat* temp;
    IplImage* temp_img = cvCreateImage(cvSize(img_size.width,img_size.height),8,3);

//-----------
    temp = (CvMat*)temp_img;
    _src_points = temp;
    errcount += run_test_case( CV_StsAssert, "Input data is not CvMat*" );
    _src_points = &_src_points_orig;

    temp = (CvMat*)temp_img;
    _dst_points = temp;
    errcount += run_test_case( CV_StsAssert, "Output data is not CvMat*" );
    _dst_points = &_dst_points_orig;

    temp = cvCreateMat(2,3,CV_64F);
    _src_points = temp;
    errcount += run_test_case( CV_StsAssert, "Invalid input data matrix size" );
    _src_points = &_src_points_orig;
    cvReleaseMat(&temp);

    temp = cvCreateMat(2,3,CV_64F);
    _dst_points = temp;
    errcount += run_test_case(CV_StsAssert, "Invalid output data matrix size" );
    _dst_points = &_dst_points_orig;
    cvReleaseMat(&temp);

    temp = cvCreateMat(1,3,CV_64F);
    temp1 = cvCreateMat(4,1,CV_64F);
    _dst_points = temp;
    _src_points = temp1;
    errcount += run_test_case(CV_StsAssert, "Output and input data sizes mismatch" );
    _dst_points = &_dst_points_orig;
    _src_points = &_src_points_orig;
    cvReleaseMat(&temp);
    cvReleaseMat(&temp1);

    temp = cvCreateMat(1,3,CV_32S);
    _dst_points = temp;
    errcount += run_test_case(CV_StsAssert, "Invalid output data matrix type" );
    _dst_points = &_dst_points_orig;
    cvReleaseMat(&temp);

    temp = cvCreateMat(1,3,CV_32S);
    _src_points = temp;
    errcount += run_test_case(CV_StsAssert, "Invalid input data matrix type" );
    _src_points = &_src_points_orig;
    cvReleaseMat(&temp);
//------------
    temp = cvCreateMat(2,3,CV_64F);
    _camera_mat = temp;
    errcount += run_test_case( CV_StsAssert, "Invalid camera data matrix size" );
    _camera_mat = &_camera_mat_orig;
    cvReleaseMat(&temp);

    temp = cvCreateMat(3,4,CV_64F);
    _camera_mat = temp;
    errcount += run_test_case( CV_StsAssert, "Invalid camera data matrix size" );
    _camera_mat = &_camera_mat_orig;
    cvReleaseMat(&temp);

    temp = (CvMat*)temp_img;
    _camera_mat = temp;
    errcount += run_test_case( CV_StsAssert, "Camera data is not CvMat*" );
    _camera_mat = &_camera_mat_orig;
//----------

    temp = (CvMat*)temp_img;
    _distortion_coeffs = temp;
    errcount += run_test_case( CV_StsAssert, "Distortion coefficients data is not CvMat*" );
    _distortion_coeffs = &_distortion_coeffs_orig;

    temp = cvCreateMat(1,6,CV_64F);
    _distortion_coeffs = temp;
    errcount += run_test_case( CV_StsAssert, "Invalid distortion coefficients data matrix size" );
    _distortion_coeffs = &_distortion_coeffs_orig;
    cvReleaseMat(&temp);

    temp = cvCreateMat(3,3,CV_64F);
    _distortion_coeffs = temp;
    errcount += run_test_case( CV_StsAssert, "Invalid distortion coefficients data matrix size" );
    _distortion_coeffs = &_distortion_coeffs_orig;
    cvReleaseMat(&temp);
//----------
    temp = (CvMat*)temp_img;
    matR = temp;
    errcount += run_test_case( CV_StsAssert, "R data is not CvMat*" );
    matR = &_R_orig;

    temp = cvCreateMat(4,3,CV_64F);
    matR = temp;
    errcount += run_test_case( CV_StsAssert, "Invalid R data matrix size" );
    matR = &_R_orig;
    cvReleaseMat(&temp);

    temp = cvCreateMat(3,2,CV_64F);
    matR = temp;
    errcount += run_test_case( CV_StsAssert, "Invalid R data matrix size" );
    matR = &_R_orig;
    cvReleaseMat(&temp);

//-----------
    temp = (CvMat*)temp_img;
    matP = temp;
    errcount += run_test_case( CV_StsAssert, "P data is not CvMat*" );
    matP = &_P_orig;

    temp = cvCreateMat(4,3,CV_64F);
    matP = temp;
    errcount += run_test_case( CV_StsAssert, "Invalid P data matrix size" );
    matP = &_P_orig;
    cvReleaseMat(&temp);

    temp = cvCreateMat(3,2,CV_64F);
    matP = temp;
    errcount += run_test_case( CV_StsAssert, "Invalid P data matrix size" );
    matP = &_P_orig;
    cvReleaseMat(&temp);
//------------
    //C++ tests
    useCPlus = true;

    camera_mat = cv::cvarrToMat(&_camera_mat_orig);
    distortion_coeffs = cv::cvarrToMat(&_distortion_coeffs_orig);
    P = cv::cvarrToMat(&_P_orig);
    R = cv::cvarrToMat(&_R_orig);
    src_points = cv::cvarrToMat(&_src_points_orig);

    temp = cvCreateMat(2,2,CV_32FC2);
    src_points = cv::cvarrToMat(temp);
    errcount += run_test_case( CV_StsAssert, "Invalid input data matrix size" );
    src_points = cv::cvarrToMat(&_src_points_orig);
    cvReleaseMat(&temp);

    temp = cvCreateMat(1,4,CV_64FC2);
    src_points = cv::cvarrToMat(temp);
    errcount += run_test_case( CV_StsAssert, "Invalid input data matrix type" );
    src_points = cv::cvarrToMat(&_src_points_orig);
    cvReleaseMat(&temp);

    src_points = cv::Mat();
    errcount += run_test_case( CV_StsAssert, "Input data matrix is not continuous" );
    src_points = cv::cvarrToMat(&_src_points_orig);
    cvReleaseMat(&temp);



//------------
    cvReleaseImage(&temp_img);
    ts->set_failed_test_info(errcount > 0 ? cvtest::TS::FAIL_BAD_ARG_CHECK : cvtest::TS::OK);
}
Exemplo n.º 15
0
void CV_UndistortBadArgTest::run(int)
{
    int errcount = 0;
//initializing
    img_size.width = 800;
    img_size.height = 600;
    double cam[9] = {150.f, 0.f, img_size.width/2.f, 0, 300.f, img_size.height/2.f, 0.f, 0.f, 1.f};
    double dist[4] = {0.01,0.02,0.001,0.0005};
    float* arr_src = new float[img_size.width*img_size.height];
    float* arr_dst = new float[img_size.width*img_size.height];
    double arr_new_camera_mat[9] = {155.f, 0.f, img_size.width/2.f+img_size.width/50.f, 0, 310.f, img_size.height/2.f+img_size.height/50.f, 0.f, 0.f, 1.f};

    CvMat _camera_mat_orig = cvMat(3,3,CV_64F,cam);
    CvMat _distortion_coeffs_orig = cvMat(1,4,CV_64F,dist);
    CvMat _new_camera_mat_orig = cvMat(3,3,CV_64F,arr_new_camera_mat);
    CvMat _src_orig = cvMat(img_size.height,img_size.width,CV_32FC1,arr_src);
    CvMat _dst_orig = cvMat(img_size.height,img_size.width,CV_32FC1,arr_dst);

    _camera_mat = &_camera_mat_orig;
    _distortion_coeffs = &_distortion_coeffs_orig;
    _new_camera_mat = &_new_camera_mat_orig;
    _src = &_src_orig;
    _dst = &_dst_orig;

//tests
    useCPlus = true;
    CvMat* temp;
    CvMat* temp1;

//C tests
    useCPlus = false;

    temp = cvCreateMat(800,600,CV_32F);
    temp1 = cvCreateMat(800,601,CV_32F);
    _src = temp;
    _dst = temp1;
    errcount += run_test_case( CV_StsAssert, "Input and output data matrix sizes mismatch" );
    _src = &_src_orig;
    _dst = &_dst_orig;
    cvReleaseMat(&temp);
    cvReleaseMat(&temp1);

    temp = cvCreateMat(800,600,CV_32F);
    temp1 = cvCreateMat(800,600,CV_64F);
    _src = temp;
    _dst = temp1;
    errcount += run_test_case( CV_StsAssert, "Input and output data matrix types mismatch" );
    _src = &_src_orig;
    _dst = &_dst_orig;
    cvReleaseMat(&temp);
    cvReleaseMat(&temp1);

    //C++ tests
    useCPlus = true;

    camera_mat = cv::cvarrToMat(&_camera_mat_orig);
    distortion_coeffs = cv::cvarrToMat(&_distortion_coeffs_orig);
    new_camera_mat = cv::cvarrToMat(&_new_camera_mat_orig);
    src = cv::cvarrToMat(&_src_orig);
    dst = cv::cvarrToMat(&_dst_orig);

//------------
    delete[] arr_src;
    delete[] arr_dst;
    ts->set_failed_test_info(errcount > 0 ? cvtest::TS::FAIL_BAD_ARG_CHECK : cvtest::TS::OK);
}
Exemplo n.º 16
0
void CV_InitUndistortRectifyMapBadArgTest::run(int)
{
    int errcount = 0;
//initializing
    img_size.width = 800;
    img_size.height = 600;
    double cam[9] = {150.f, 0.f, img_size.width/2.f, 0, 300.f, img_size.height/2.f, 0.f, 0.f, 1.f};
    double dist[4] = {0.01,0.02,0.001,0.0005};
    float* arr_mapx = new float[img_size.width*img_size.height];
    float* arr_mapy = new float[img_size.width*img_size.height];
    double arr_new_camera_mat[9] = {155.f, 0.f, img_size.width/2.f+img_size.width/50.f, 0, 310.f, img_size.height/2.f+img_size.height/50.f, 0.f, 0.f, 1.f};
    double r[9] = {1,0,0,0,1,0,0,0,1};

    CvMat _camera_mat_orig = cvMat(3,3,CV_64F,cam);
    CvMat _distortion_coeffs_orig = cvMat(1,4,CV_64F,dist);
    CvMat _new_camera_mat_orig = cvMat(3,3,CV_64F,arr_new_camera_mat);
    CvMat _R_orig = cvMat(3,3,CV_64F,r);
    CvMat _mapx_orig = cvMat(img_size.height,img_size.width,CV_32FC1,arr_mapx);
    CvMat _mapy_orig = cvMat(img_size.height,img_size.width,CV_32FC1,arr_mapy);
    int mat_type_orig = CV_32FC1;

    _camera_mat = &_camera_mat_orig;
    _distortion_coeffs = &_distortion_coeffs_orig;
    _new_camera_mat = &_new_camera_mat_orig;
    matR = &_R_orig;
    _mapx = &_mapx_orig;
    _mapy = &_mapy_orig;
    mat_type = mat_type_orig;

//tests
    useCPlus = true;
    CvMat* temp;

    //C++ tests
    useCPlus = true;

    camera_mat = cv::cvarrToMat(&_camera_mat_orig);
    distortion_coeffs = cv::cvarrToMat(&_distortion_coeffs_orig);
    new_camera_mat = cv::cvarrToMat(&_new_camera_mat_orig);
    R = cv::cvarrToMat(&_R_orig);
    mapx = cv::cvarrToMat(&_mapx_orig);
    mapy = cv::cvarrToMat(&_mapy_orig);


    mat_type = CV_64F;
    errcount += run_test_case( CV_StsAssert, "Invalid map matrix type" );
    mat_type = mat_type_orig;

    temp = cvCreateMat(3,2,CV_32FC1);
    camera_mat = cv::cvarrToMat(temp);
    errcount += run_test_case( CV_StsAssert, "Invalid camera data matrix size" );
    camera_mat = cv::cvarrToMat(&_camera_mat_orig);
    cvReleaseMat(&temp);

    temp = cvCreateMat(4,3,CV_32FC1);
    R = cv::cvarrToMat(temp);
    errcount += run_test_case( CV_StsAssert, "Invalid R data matrix size" );
    R = cv::cvarrToMat(&_R_orig);
    cvReleaseMat(&temp);

    temp = cvCreateMat(6,1,CV_32FC1);
    distortion_coeffs = cv::cvarrToMat(temp);
    errcount += run_test_case( CV_StsAssert, "Invalid distortion coefficients data matrix size" );
    distortion_coeffs = cv::cvarrToMat(&_distortion_coeffs_orig);
    cvReleaseMat(&temp);

//------------
    delete[] arr_mapx;
    delete[] arr_mapy;
    ts->set_failed_test_info(errcount > 0 ? cvtest::TS::FAIL_BAD_ARG_CHECK : cvtest::TS::OK);
}