コード例 #1
0
ファイル: unittest.c プロジェクト: emmaggie/starcode
int
run_unittest
(
         int            argc,
         char        ** argv,
   const test_case_t  * test_case_list[]
)
{

   // Initialize test set. //
   unit_test_init();

   pthread_t tid;

   int nbad = 0;

   // Run test cases in sequential order.
   for (int j = 0 ; test_case_list[j] != NULL ; j++) {

      const test_case_t *test_cases = test_case_list[j];
      for (int i = 0 ; test_cases[i].fixture != NULL ; i++) {

         // Some verbose information. //
         fprintf(stderr, "%s\n", test_cases[i].test_name);

         // Run test case in thread. //
         pthread_create(&tid, NULL, run_testset, (void *) &test_cases[i]);
         pthread_join(tid, NULL);

         nbad += TEST_CASE_FAILED;

      }

   }

   // Clean and return. //
   unit_test_clean();
   return nbad;

}
コード例 #2
0
ファイル: unittest.c プロジェクト: ezorita/mapper
int
run_unittest
(
         int            argc,
         char        ** argv,
   const test_case_t  * test_case_list[]
)
{

   machine_specific_initialization();

	// Parse command line options.
   while(1) {
      int option_index = 0;
      static struct option long_options[] = {
         {"showall", no_argument, &SHOWALL,  1},
         {"inspect", no_argument, &INSPECT,  1},
         {0, 0, 0, 0}
      };

      int c = getopt_long(argc, argv, "ai",
            long_options, &option_index);

      // Done parsing named options. //
      if (c == -1) break;

      switch (c) {
      case 0:
         break;
		case 'a':
			SHOWALL = 1;
			break;
		case 'i':
			INSPECT = 1;
			break;
		default:
			fprintf(stderr, "cannot parse command line arguments\n");
			return EXIT_FAILURE;
		}
	}

   // Initialize test. //
   unit_test_init();

   pthread_t tid;

   int nbad = 0;

   // Run test cases in sequential order.
   for (int j = 0 ; test_case_list[j] != NULL ; j++) {

      const test_case_t *tests = test_case_list[j];
      for (int i = 0 ; tests[i].fixture != NULL ; i++) {

         // Display of the test. //
         fprintf(stderr, "%s%*s", tests[i].test_name,
                  28 - (int) strlen(tests[i].test_name), "");

         // Run test case in thread. //
         pthread_create(&tid, NULL, run_test, (void *) &tests[i]);
         pthread_join(tid, NULL);

         if (TEST_CASE_FAILED) {
				// Display was updated if test failed. 
            nbad++;
         }
         else {
            update_display_success();
         }

      }

   }

   // Clean and return. //
   unit_test_clean();
   return nbad;

}