exportheader_test.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #include "libshared.h"
  2. #include "libstatic.h"
  3. // #define BUILD_FAIL
  4. #ifndef BUILD_FAIL
  5. #define DOES_NOT_BUILD(function)
  6. #else
  7. #define DOES_NOT_BUILD(function) function
  8. #endif
  9. #include <fstream>
  10. #include <iostream>
  11. #include <stdlib.h>
  12. #include <string>
  13. void compare(const char* refName, const char* testName)
  14. {
  15. std::ifstream ref;
  16. ref.open(refName);
  17. if (!ref.is_open())
  18. {
  19. std::cout << "Could not open \"" << refName << "\"." << std::endl;
  20. exit(1);
  21. }
  22. std::ifstream test;
  23. test.open(testName);
  24. if (!test.is_open())
  25. {
  26. std::cout << "Could not open \"" << testName << "\"." << std::endl;
  27. exit(1);
  28. }
  29. while (!ref.eof() && !test.eof())
  30. {
  31. std::string refLine;
  32. std::string testLine;
  33. std::getline(ref, refLine);
  34. std::getline(test, testLine);
  35. if (testLine.size() && testLine[testLine.size()-1] == ' ')
  36. {
  37. testLine = testLine.substr(0, testLine.size() - 1);
  38. }
  39. if (refLine != testLine)
  40. {
  41. std::cout << "Ref and test are not the same:\n Ref: \""
  42. << refLine << "\"\n Test: \"" << testLine << "\"\n";
  43. exit(1);
  44. }
  45. }
  46. if (!ref.eof() || !test.eof())
  47. {
  48. std::cout << "Ref and test have differing numbers of lines.";
  49. exit(1);
  50. }
  51. }
  52. int main()
  53. {
  54. {
  55. Libshared l;
  56. l.libshared();
  57. l.libshared_exported();
  58. l.libshared_deprecated();
  59. l.libshared_not_exported();
  60. DOES_NOT_BUILD(l.libshared_excluded();)
  61. }
  62. {
  63. LibsharedNotExported l;
  64. DOES_NOT_BUILD(l.libshared();)
  65. l.libshared_exported();
  66. l.libshared_deprecated();
  67. DOES_NOT_BUILD(l.libshared_not_exported();)
  68. DOES_NOT_BUILD(l.libshared_excluded();)
  69. }
  70. {
  71. LibsharedExcluded l;
  72. DOES_NOT_BUILD(l.libshared();)
  73. l.libshared_exported();
  74. l.libshared_deprecated();
  75. DOES_NOT_BUILD(l.libshared_not_exported();)
  76. DOES_NOT_BUILD(l.libshared_excluded();)
  77. }
  78. libshared_exported();
  79. libshared_deprecated();
  80. DOES_NOT_BUILD(libshared_not_exported();)
  81. DOES_NOT_BUILD(libshared_excluded();)
  82. {
  83. Libstatic l;
  84. l.libstatic();
  85. l.libstatic_exported();
  86. l.libstatic_deprecated();
  87. l.libstatic_not_exported();
  88. l.libstatic_excluded();
  89. }
  90. {
  91. LibstaticNotExported l;
  92. l.libstatic();
  93. l.libstatic_exported();
  94. l.libstatic_deprecated();
  95. l.libstatic_not_exported();
  96. l.libstatic_excluded();
  97. }
  98. {
  99. LibstaticExcluded l;
  100. l.libstatic();
  101. l.libstatic_exported();
  102. l.libstatic_deprecated();
  103. l.libstatic_not_exported();
  104. l.libstatic_excluded();
  105. }
  106. libstatic_exported();
  107. libstatic_deprecated();
  108. libstatic_not_exported();
  109. libstatic_excluded();
  110. #define STRINGIFY_IMPL(A) #A
  111. #define STRINGIFY(A) STRINGIFY_IMPL(A)
  112. compare(STRINGIFY(SRC_DIR) "/libshared_export.h",
  113. STRINGIFY(BIN_DIR) "/libshared/libshared_export.h");
  114. compare(STRINGIFY(SRC_DIR) "/libstatic_export.h",
  115. STRINGIFY(BIN_DIR) "/libstatic/libstatic_export.h");
  116. return 0;
  117. }