SHARE
TWEET

Untitled

a guest Mar 19th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CPPFLAGS += -I$(CPPUTEST_HOME)/include
  2. CXXFLAGS += -include $(CPPUTEST_HOME)/include/CppUTest/MemoryLeakDetectorNewMacros.h
  3. CFLAGS += -include $(CPPUTEST_HOME)/include/CppUTest/MemoryLeakDetectorMallocMacros.h
  4. LD_LIBRARIES = -L$(CPPUTEST_HOME)/lib -lCppUTest -lCppUTestExt
  5.  
  6. all:
  7.         c++ -g -Wall $(CPPFLAGS) $(CXXFLAGS) $(CFLAGS) commonTest.cpp -o commonTest $(LD_LIBRARIES)
  8.  
  9. clean:
  10.         rm -rf *.dSYM commonTest
  11.      
  12. Undefined symbols for architecture x86_64:
  13.   "_test_common_algos_commonCalloc_wrapper_c", referenced from:
  14.       TEST_common_algos_commonCalloc_Test::testBody() in commonTest-992552.o
  15.   "_test_common_algos_commonMalloc_wrapper_c", referenced from:
  16.       TEST_common_algos_commonMalloc_Test::testBody() in commonTest-992552.o
  17.   "_test_common_algos_commonRealloc_wrapper_c", referenced from:
  18.       TEST_common_algos_commonRealloc_Test::testBody() in commonTest-992552.o
  19. ld: symbol(s) not found for architecture x86_64
  20. clang: error: linker command failed with exit code 1 (use -v to see invocation)
  21. make: *** [all] Error 1
  22.      
  23. #include "../common.h"
  24. #include "CppUTest/TestHarness_c.h"
  25.  
  26. void *ptr = NULL;
  27. int list[10] = {1, 2, 32, 33, 2, 5, 7, 3, 9, 34};
  28.  
  29. TEST_GROUP_C_WRAPPER(common_algos)
  30. {
  31.  
  32. };
  33.  
  34. TEST_C(common_algos, commonMalloc)
  35. {
  36.   ptr = malloc_c(6);
  37.   CHECK_EQUAL_C_INT(algos_error, ALGOS_OK);
  38.   strncpy(ptr, "Hello", 5);
  39.   CHECK_EQUAL_C_STRING("Hello", ptr);
  40.   free_c(ptr);
  41. }
  42.  
  43. TEST_C(common_algos, commonCalloc)
  44. {
  45.   ptr = calloc_c(sizeof(int), 10);
  46.   CHECK_EQUAL_C_INT(algos_error, ALGOS_OK);
  47.   memcpy(ptr, list, sizeof(int)*10);
  48.   for (int i = 0; i < 10; i++)
  49.       CHECK_EQUAL_C_INT(list[i], ptr[i]);
  50.   free_c(ptr);
  51. }
  52.  
  53. TEST_C(common_algos, commonRealloc)
  54. {
  55.   ptr = malloc_c(10);
  56.   CHECK_EQUAL_C_INT(ALGOS_OK, algos_error);
  57.   memcpy(ptr, list, sizeof(int)*10);
  58.   ptr = realloc_c(ptr, 20);
  59.   CHECK_EQUAL_C_INT(ALGOS_OK, algos_error);
  60.   memcpy(ptr + 10, list, sizeof(int)*10);
  61.   for (int i = 9; i < 19; i++)
  62.       CHECK_EQUAL_C_INT(list[i-9], ptr[i]);
  63.   free_c(ptr);
  64. }
  65.      
  66. #include "CppUTest/CommandLineTestRunner.h"
  67. #include "CppUTest/TestHarness_c.h"
  68.  
  69. TEST_GROUP_C_WRAPPER(common_algos)
  70. {
  71.  
  72. };
  73.  
  74. TEST_C_WRAPPER(common_algos, commonMalloc);
  75. TEST_C_WRAPPER(common_algos, commonCalloc);
  76. TEST_C_WRAPPER(common_algos, commonRealloc);
  77.  
  78.  
  79. int main(int ac, char **av)
  80. {
  81.  return RUN_ALL_TESTS(ac, av);
  82. }
  83.      
  84. common
  85.   |______ common.c
  86.   |
  87.   |______ common.h
  88.   |
  89.   |______ test
  90.            |
  91.            |____commonTest.c
  92.            |
  93.            |____commonTest.cpp
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top