Beispiel #1
0
void choose_test()
{
    AK_PRO;
    int ans=-1;
    AK_create_test_tables();
    set_catalog_constraints();
    while(ans)
    {
        printf("\n\n\n");
        show_test();
        printf("Test: ");
        scanf("%d", &ans);
        while(ans<0 && ans>32)
        {
            printf("\nTest: ");
            scanf("%d", &ans);
        }
        if(ans)
        {
            ans--;
            fun[ans].func();
            printf("\n\nPress Enter to continue:");
            getchar();
            getchar();
            ans++;
        }
    }
    AK_EPI;
}
Beispiel #2
0
int main()
{
  size_t count = 1000;
  bool show = false;
  protobuf_init();  
  std::cout << "#######################" << std::endl;
  std::cout << "#### serialization ####" << std::endl;
  std::cout << "====    request    ====" << std::endl;
  show_test( f_test<request, empty_serialize, false>("empty_serialize"), count, show);
  show_test( f_test<request, sprintf_serialize, false>("sprintf_serialize"), count, show);
  show_test( f_test<request, fasjson_serialize, false>("fasjson_serialize"), count, show);
  show_test( f_test<request, protobuf_serialize, false>("protobuf_serialize"), count, show);
  std::cout << "====    response    ====" << std::endl;
  show_test( f_test<response, empty_serialize, false>("empty_serialize"), count, show);
  show_test( f_test<response, sprintf_serialize, false>("sprintf_serialize"), count, show);
  show_test( f_test<response, fasjson_serialize, false>("fasjson_serialize"), count, show);
  show_test( f_test<response, protobuf_serialize, false>("protobuf_serialize"), count, show);

  std::cout << "#########################" << std::endl;
  std::cout << "#### deserialization ####" << std::endl;
  std::cout << "====    request    ====" << std::endl;
  show_test( f_test<request, empty_deserialize, false>("empty_deserialize"), count, show);
  show_test( f_test<request, sprintf_deserialize, false>("sprintf_deserialize"), count, show);
  show_test( f_test<request, fasjson_deserialize, false>("fasjson_deserialize"), count, show);
  show_test( f_test<request, fasoldjson_deserialize, false>("fasoldjson_deserialize"), count, show);
  show_test( f_test<request, protobuf_deserialize, false>("protobuf_deserialize"), count, show);
  std::cout << "====    response    ====" << std::endl;
  show_test( f_test<response, empty_deserialize, false>("empty_deserialize"), count, show);
  
  show_test( f_test<response, sprintf_deserialize, false>("sprintf_deserialize"), count, show);
  
  show_test( f_test<response, fasjson_deserialize, false>("fasjson_deserialize"), count, show);
  show_test( f_test<response, protobuf_deserialize, false>("protobuf_deserialize"), count, show);
  /*
  std::cout << "#######################" << std::endl;
  std::cout << "#### serialization ####" << std::endl;
  std::cout << "====    request    ====" << std::endl;
  std::cout << "----    char*      ----" << std::endl;
  show_test( f_serialize_cstr<request, empty_serialize>("empty_serialize"), count, show);
  std::cout << "----  std::string  ----" << std::endl;
  show_test( f_serialize_string<request, empty_serialize>("empty_serialize"), count, show);
  std::cout << "====    response    ====" << std::endl;
  std::cout << "----    char*      ----" << std::endl;
  show_test( f_serialize_cstr<response, empty_serialize>("empty_serialize"), count, show);
  std::cout << "----  std::string  ----" << std::endl;
  show_test( f_serialize_string<response, empty_serialize>("empty_serialize"), count, show);
  */
}
Beispiel #3
0
int main() {
  int32_t x, y;
  uint32_t a, b, n;
  char c;
  string_buffer_t *s;

  s = &buffer;
  init_string_buffer(s, 0);
  show_test("empty buffer", s);

  string_buffer_reset(s);
  for (c = 'a'; c <= 'z'; c++) {
    string_buffer_append_char(s, c);
  }
  show_test("alphabet", s);

  string_buffer_reset(s);
  for (c = 'a'; c <= 'z'; c++) {
    string_buffer_append_char(s, c);
  }
  string_buffer_append_string(s, "au898ue2bcc90219");
  show_test("alphabet+au898ue2bcc90219", s);

  x = INT32_MIN;
  for (;;){
    sprintf(aux, "signed number: %" PRId32, x);
    string_buffer_reset(s);
    string_buffer_append_int32(s, x);
    show_test(aux, s);
    y = x >> 1;
    if (y == x) break;
    x = y;
  }

  x = INT32_MAX;
  for (;;) {
    sprintf(aux, "signed number: %" PRId32, x);
    string_buffer_reset(s);
    string_buffer_append_int32(s, x);
    show_test(aux, s);
    y = x>>1;
    if (y == x) break;
    x = y;
  }

  a = UINT32_MAX;
  for (;;){
    sprintf(aux, "unsigned number: %" PRIu32, a);
    string_buffer_reset(s);
    string_buffer_append_uint32(s, a);
    show_test(aux, s);
    b = a >> 1;
    if (b == a) break;
    a = b;
  }

  mpz_init(z0);
  mpz_init(z1);
  mpq_init(q0);

  mpz_set_str(z0, "111102222033330123456789", 10);
  string_buffer_reset(s);
  string_buffer_append_mpz(s, z0);
  show_test("mpz: 111102222033330123456789", s);

  mpz_set_str(z0, "-111102222033330123456789", 10);
  string_buffer_reset(s);
  string_buffer_append_mpz(s, z0);
  show_test("mpz: -111102222033330123456789", s);

  string_buffer_reset(s);
  string_buffer_append_mpz(s, z1);
  show_test("mpz: 0", s);

  mpq_set_str(q0, "-98765432109876543210", 10);
  string_buffer_reset(s);
  string_buffer_append_mpq(s, q0);
  show_test("mpq: -98765432109876543210", s);

  mpq_set_str(q0, "-98765432109876543210/38192839777", 10);
  string_buffer_reset(s);
  string_buffer_append_mpq(s, q0);
  show_test("mpq: -98765432109876543210/38192839777", s);

  init_rationals();
  rational_t r0;
  q_init(&r0);
  string_buffer_reset(s);
  string_buffer_append_rational(s, &r0);
  show_test("rational: 0", s);

  q_set_int32(&r0, -12, 73);
  string_buffer_reset(s);
  string_buffer_append_rational(s, &r0);
  show_test("rational: -12/73", s);

  q_set_mpq(&r0, q0);
  string_buffer_reset(s);
  string_buffer_append_rational(s, &r0);
  show_test("rational: -98765432109876543210/38192839777", s);

  q_set_mpz(&r0, z0);
  string_buffer_reset(s);
  string_buffer_append_rational(s, &r0);
  show_test("rational: -111102222033330123456789", s);


  printf("\nBit Vectors\n");
  init_bvconstants();
  bv0 = bvconst_alloc(1);
  bvconst_clear(bv0, 1);
  for (n=1; n<= 32; n++) {
    string_buffer_reset(s);
    string_buffer_append_bvconst(s, bv0, n);
    sprintf(aux, "bv[%" PRIu32"]: 0b000...", n);
    show_test(aux, s);
  }

  for (n=1; n <= 32; n++) {
    bvconst_clear(bv0, 1);
    bvconst_set_bit(bv0, n-1);
    string_buffer_reset(s);
    string_buffer_append_bvconst(s, bv0, n);
    sprintf(aux, "bv[%" PRIu32"]: 0b100...", n);
    show_test(aux, s);
  }


  bvconst_free(bv0, 1);

  cleanup_bvconstants();

  cleanup_rationals();

  mpz_clear(z0);
  mpz_clear(z1);
  mpq_clear(q0);

  delete_string_buffer(s);

  return 0;
}
Beispiel #4
0
/**
Main program function
@return EXIT_SUCCESS if successful, EXIT_ERROR otherwise
*/
int main(int argc, char * argv[])
{
    AK_PRO;
    // initialize critical sections
    dbmanFileLock = AK_init_critical_section();
    printf("Init: %d, ready: %d", dbmanFileLock->init, dbmanFileLock->ready);
    AK_check_folder_blobs();
    if((argc == 2) && !strcmp(argv[1], "help"))
		//if we write ./akdb test help, the help will pop up
        help();
    else if((argc == 3) && !strcmp(argv[1], "test") && !strcmp(argv[2], "show"))
		//if we write ./akdb test test or show, the inputed will start and show
        show_test();
    else
    {
        printf( "KALASHNIKOV DB - STARTING\n\n" );
        AK_inflate_config();
        printf("db_file: %s\n", DB_FILE);
	testMode = TEST_MODE_OFF;
        if( AK_init_disk_manager() == EXIT_SUCCESS )
        {
                if( AK_memoman_init() == EXIT_SUCCESS )
                {
            /* component test area --- begin */
            if((argc == 2) && !strcmp(argv[1], "test"))
            {
		//if we write 2 arguments, choose test will start
                choose_test();
            }
            else if((argc == 3) && !strcmp(argv[1], "test"))
            {
		// argc - number of arguments we inputin in the comand line, which we save in the argv []
		// argv - [] pointer , 2D field in which we put and save arguments
		//if we input ./akdb test "test number", the test we inputed will start
                int ans;
		//we define an integer wich we use later
                ans = strtol(argv[2], NULL, 10)-1;
		//long int strtol(const char *str, char **endptr, int base)
		//str - string containing the representation of an integral numbe
		//endptr - reference to an object of type char*
		//base - which must be between 2 and 36 inclusive, or be the special value 0
		//long int value - min 32 bit velicine, [−2147483647,+2147483647] 
                AK_create_test_tables();
		//when we start the inputed test, first the tables will be created
                set_catalog_constraints();
                fun[ans].func();
		//after the created tables the test will start, and call the function of the test from fun[], which we defined at the begining
            }
            /*component test area --- end */
            if ( AK_flush_cache() == EXIT_SUCCESS ){
		int ans;
                ans = strtol(argv[2], NULL, 10)-1;	
		printf("\nTEST:--- %s --- ENDED!\n", fun[ans].name);
		//if the test started and ended with a success, we will be informed with this message and with the name
                printf( "\nEverything was fine!\nBye =)\n" );

                /* For easyer debugging and GDB usage
                AK_create_test_tables();
                AK_view_test();
                */
                //            pthread_exit(NULL);
		AK_EPI;
                return ( EXIT_SUCCESS );
            }
        }
                printf( "ERROR. Failed to initialize memory manager\n" );
		AK_EPI;
                return ( EXIT_ERROR );
        }
        printf( "ERROR. Failed to initialize disk manager\n" );
	AK_EPI;
	int br = 3;
    printf("Izaberite broj testa koji želite pokrenuti: \n");
    scanf("%i",&br);
        return ( EXIT_ERROR );
    }
    // delete critical sections
    AK_destroy_critical_section(dbmanFileLock);
    AK_EPI;
    return(EXIT_SUCCESS);
}//main