apitest_cxxtest.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #ifndef APITEST_CXXTEST_H
  2. #define APITEST_CXXTEST_H
  3. #include <typeinfo>
  4. #include <iostream>
  5. #include <cxxtest/TestSuite.h>
  6. using namespace std;
  7. using namespace CxxTest;
  8. struct TableEntry
  9. {
  10. int a;
  11. std::string b;
  12. double c;
  13. };
  14. TableEntry MyTable[] = {
  15. {4, "hugo", 3.3},
  16. {5, "emma", 4.4},
  17. };
  18. #define N_TABLE_ITEMS (sizeof(MyTable)/sizeof(TableEntry))
  19. class ApiTest_CxxTest : public CxxTest::TestSuite
  20. {
  21. public:
  22. void testAssertEquals()
  23. {
  24. int a=2;
  25. int b=4;
  26. TS_ASSERT_DIFFERS(a,b);
  27. }
  28. void XtestStringAssert()
  29. {
  30. string a="hallo";
  31. string b="otto";
  32. string c="otto";
  33. TS_ASSERT_EQUALS(a,b);
  34. TS_ASSERT_EQUALS(b,c);
  35. }
  36. void testStringLiteralAssert()
  37. {
  38. char a[]="alal";
  39. char b[]="gugu";
  40. string A="alal";
  41. string B="gugu";
  42. TS_ASSERT_EQUALS(a, a);
  43. TS_ASSERT_EQUALS(b, B);
  44. }
  45. void testTypeInfo()
  46. {
  47. string a="otto";
  48. string a_quoted = string("\"") + a + "\"";
  49. string b="hallo";
  50. cout << "TypeInfo=" << typeid(a).name() << "\n";
  51. cout << "TypeInfo=" << typeid(CxxTest::traits(a)).name() << "\n";
  52. cout << "TypeInfo=" << typeid(CxxTest::traits(b)).name() << "\n";
  53. cout << "TS_AS_STRING(x) = " << TS_AS_STRING(a) << "\n";
  54. string otto =TS_AS_STRING(a);
  55. TS_ASSERT_EQUALS(a_quoted, otto);
  56. }
  57. void testCppTable()
  58. {
  59. TS_ASSERT_EQUALS(MyTable[0].a, 4);
  60. TS_ASSERT_EQUALS(MyTable[1].a, 5);
  61. TS_ASSERT_EQUALS(N_TABLE_ITEMS, 2);
  62. }
  63. };
  64. #endif // APITEST_CXXTEST_H