void test_CU_malloc(void) { void* ptr1 = NULL; void* ptr2 = malloc(sizeof(int)); unsigned int n2 = test_cunit_get_n_memevents(ptr2); /* test allocation failure */ test_cunit_deactivate_malloc(); ptr1 = CU_MALLOC(sizeof(int)); TEST(NULL == ptr1); TEST(test_cunit_get_n_allocations(ptr1) == test_cunit_get_n_deallocations(ptr1)); TEST(test_cunit_get_n_allocations(ptr2) == test_cunit_get_n_deallocations(ptr2)); test_cunit_activate_malloc(); /* normal allocation */ ptr1 = CU_MALLOC(sizeof(int)); TEST_FATAL(NULL != ptr1); TEST(test_cunit_get_n_allocations(ptr1) != test_cunit_get_n_deallocations(ptr1)); TEST(test_cunit_get_n_allocations(ptr2) == test_cunit_get_n_deallocations(ptr2)); CU_FREE(ptr1); TEST(test_cunit_get_n_allocations(ptr1) == test_cunit_get_n_deallocations(ptr1)); TEST(test_cunit_get_n_allocations(ptr2) == test_cunit_get_n_deallocations(ptr2)); TEST(n2 == test_cunit_get_n_memevents(ptr2)); free(ptr2); }
void test_CU_realloc(void) { void* ptr1 = CU_MALLOC(sizeof(int)); void* ptr2 = malloc(sizeof(int)); void* ptr3; void* ptr4; unsigned int n2 = test_cunit_get_n_memevents(ptr2); /* test allocation failure */ test_cunit_deactivate_malloc(); ptr1 = CU_REALLOC(ptr1, sizeof(long int)); TEST(NULL == ptr1); TEST(test_cunit_get_n_allocations(ptr1) == test_cunit_get_n_deallocations(ptr1)); TEST(test_cunit_get_n_allocations(ptr2) == test_cunit_get_n_deallocations(ptr2)); test_cunit_activate_malloc(); /* normal allocation */ ptr3 = CU_MALLOC(sizeof(int)); TEST_FATAL(NULL != ptr3); TEST(test_cunit_get_n_allocations(ptr1) == test_cunit_get_n_deallocations(ptr1)); TEST(test_cunit_get_n_allocations(ptr2) == test_cunit_get_n_deallocations(ptr2)); TEST(test_cunit_get_n_allocations(ptr3) != test_cunit_get_n_deallocations(ptr3)); ptr4 = CU_REALLOC(ptr3, sizeof(long int)); TEST_FATAL(NULL != ptr4); TEST(test_cunit_get_n_allocations(ptr1) == test_cunit_get_n_deallocations(ptr1)); TEST(test_cunit_get_n_allocations(ptr2) == test_cunit_get_n_deallocations(ptr2)); if (ptr3 != ptr4) TEST(test_cunit_get_n_allocations(ptr3) == test_cunit_get_n_deallocations(ptr3)); TEST(test_cunit_get_n_allocations(ptr4) != test_cunit_get_n_deallocations(ptr4)); CU_FREE(ptr4); TEST(test_cunit_get_n_allocations(ptr1) == test_cunit_get_n_deallocations(ptr1)); TEST(test_cunit_get_n_allocations(ptr2) == test_cunit_get_n_deallocations(ptr2)); TEST(test_cunit_get_n_allocations(ptr3) == test_cunit_get_n_deallocations(ptr3)); TEST(test_cunit_get_n_allocations(ptr4) == test_cunit_get_n_deallocations(ptr4)); TEST(n2 == test_cunit_get_n_memevents(ptr2)); free(ptr2); }
void Test::testFailures() { // Non-existing long option { AppOptions opts("myapp -b --uintopt 4 -s foo --none"); MyOptions options(opts.getArgCount(), opts.getArguments()); try{ options.parse(); TEST_FATAL("Expected exception"); } catch (InvalidCommandLineArgumentsException& e) { EXPECT_EQUAL("Invalid option 'none'.", e.getMessage()); } } // Non-existing short option { AppOptions opts("myapp -b --uintopt 4 -s foo -q"); MyOptions options(opts.getArgCount(), opts.getArguments()); try{ options.parse(); TEST_FATAL("Expected exception"); } catch (InvalidCommandLineArgumentsException& e) { EXPECT_EQUAL("Invalid option 'q'.", e.getMessage()); } } // Lacking option argument { AppOptions opts("myapp -b --uintopt 4 -s"); MyOptions options(opts.getArgCount(), opts.getArguments()); try{ options.parse(); TEST_FATAL("Expected exception"); } catch (InvalidCommandLineArgumentsException& e) { EXPECT_EQUAL("Option 's' needs 1 arguments. Only 0 available.", e.getMessage()); } } // Out of signed ranged { AppOptions opts("myapp -b --uintopt 4 -intopt 3000000000"); MyOptions options(opts.getArgCount(), opts.getArguments()); try{ options.parse(); TEST_FATAL("Expected exception"); } catch (InvalidCommandLineArgumentsException& e) { EXPECT_EQUAL("The argument '3000000000' can not be interpreted as a " "number of type int.", e.getMessage()); } } // Negative value to unsigned var (Currently doesnt fail) /* { AppOptions opts("myapp -b --uintopt -1 foo 0"); MyOptions options(opts.getArgCount(), opts.getArguments()); try{ options.parse(); TEST_FATAL("Expected exception"); } catch (InvalidCommandLineArgumentsException& e) { EXPECT_EQUAL("The argument '-1' can not be interpreted as a " "number of type uint.", e.getMessage()); } } */ // Lacking required option { AppOptions opts("myapp -b"); MyOptions options(opts.getArgCount(), opts.getArguments()); try{ options.parse(); TEST_FATAL("Expected exception"); } catch (InvalidCommandLineArgumentsException& e) { EXPECT_EQUAL("Option 'uintopt' has no default and must be set.", e.getMessage()); } } // Lacking required argument { AppOptions opts("myapp --uintopt 1 tit"); MyOptions options(opts.getArgCount(), opts.getArguments()); try{ options.parse(); TEST_FATAL("Expected exception"); } catch (InvalidCommandLineArgumentsException& e) { EXPECT_EQUAL("Insufficient data is given to set required argument " "'argInt'.", e.getMessage()); } } // Argument of wrong type { AppOptions opts("myapp --uintopt 1 tit en"); MyOptions options(opts.getArgCount(), opts.getArguments()); try{ options.parse(); TEST_FATAL("Expected exception"); } catch (InvalidCommandLineArgumentsException& e) { EXPECT_EQUAL("The argument 'en' can not be interpreted as a number " "of type int.", e.getMessage()); } } }
int main(int argc, char **argv) { WLM_DUT_INTERFACE dutInterface = WLM_DUT_LOCAL; char *interfaceName = 0; WLM_DUT_SERVER_PORT dutServerPort = WLM_DEFAULT_DUT_SERVER_PORT; WLM_DUT_OS dutOs = WLM_DUT_OS_WIN32; (void)argc; while (*++argv) { if (strncmp(*argv, "--help", strlen(*argv)) == 0) { printUsage(); exit(0); } if (strncmp(*argv, "--socket", strlen(*argv)) == 0) { int port; dutInterface = WLM_DUT_SOCKET; if (!*++argv) { printf("IP address required\n"); printUsage(); exit(-1); } interfaceName = *argv; if (*++argv && (sscanf(*argv, "%d", &port) == 1)) { dutServerPort = (WLM_DUT_SERVER_PORT)port; } else { /* optional parameter */ --argv; } } if (strncmp(*argv, "--serial", strlen(*argv)) == 0) { dutInterface = WLM_DUT_SERIAL; if (!*++argv) { printf("serial port required\n"); printUsage(); exit(-1); } interfaceName = *argv; } if (strncmp(*argv, "--wifi", strlen(*argv)) == 0) { dutInterface = WLM_DUT_WIFI; if (!*++argv) { printf("MAC address required\n"); printUsage(); exit(-1); } interfaceName = *argv; } if (strncmp(*argv, "--dongle", strlen(*argv)) == 0) { unsigned int i; char buffer[256]; dutInterface = WLM_DUT_DONGLE; if (!*++argv) { printf("COM port required\n"); printUsage(); exit(-1); } if (!(sscanf(*argv, "COM%u", &i) == 1 || sscanf(*argv, "/dev/tty%s", buffer) == 1)) { printf("serial port invalid\n"); printUsage(); exit(-1); } interfaceName = *argv; } if ((strncmp(*argv, "--linux", strlen(*argv)) == 0) || strncmp(*argv, "--linuxdut", strlen(*argv)) == 0) { dutOs = WLM_DUT_OS_LINUX; } } TEST_INITIALIZE(); TEST_FATAL(wlmApiInit(), "wlmApiInit failed"); TEST_FATAL(wlmSelectInterface(dutInterface, interfaceName, dutServerPort, dutOs), "wlmSelectInterface failed"); printf("\n"); switch (dutInterface) { case WLM_DUT_LOCAL: printf("Test running against local DUT.\n"); break; case WLM_DUT_SOCKET: printf("Test running over Ethernet to remote DUT IP=%s.\n", interfaceName); break; case WLM_DUT_SERIAL: printf("Test running over serial from port %s\n", interfaceName); break; case WLM_DUT_WIFI: printf("Test running over 802.11 to remote DUT MAC=%s.\n", interfaceName); break; case WLM_DUT_DONGLE: printf("Test running over serial from %s to remote dongle UART\n", interfaceName); break; default: printf("Invalid interface\n"); exit(-1); break; } switch (dutOs) { case WLM_DUT_OS_LINUX: printf("Test running against Linux DUT.\n"); break; case WLM_DUT_OS_WIN32: printf("Test running against Win32 DUT.\n"); break; default: printf("Invalid DUT OS\n"); exit(-1); break; } printf("\n"); /* packet engine requires MPC to be disabled and WLAN interface up */ TEST(wlmMinPowerConsumption(FALSE), "wlmMinPowerConsuption failed"); TEST(wlmEnableAdapterUp(TRUE), "wlmEnableAdapterUp failed"); /* invoke test cases */ testDutInit(); testVersion(); testTransmit(); testClientBatchingTransmit(); testServerBatchingTransmit(); testReceive(); testJoinNetworkNone(); testJoinNetworkWep(); testJoinNetworkWpaTkip(); testJoinNetworkWpaAes(); testJoinNetworkWpa2Tkip(); testJoinNetworkWpa2Aes(); TEST_FATAL(wlmApiCleanup(), "wlmApiCleanup failed"); TEST_FINALIZE(); return 0; }