dwp_test_1.cc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. // dwp_test_1.cc -- a test case for dwp
  2. // Copyright (C) 2012-2015 Free Software Foundation, Inc.
  3. // Written by Cary Coutant <ccoutant@google.com>.
  4. // This file is part of gold.
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 3 of the License, or
  8. // (at your option) any later version.
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  16. // MA 02110-1301, USA.
  17. // Adapted from two_file_test_1.cc.
  18. #include "dwp_test.h"
  19. // 1 Code in file 1 calls code in file 2.
  20. bool
  21. C1::testcase1()
  22. {
  23. return t1_2() == 123;
  24. }
  25. // 2 Code in file 1 refers to global data in file 2.
  26. bool
  27. C1::testcase2()
  28. {
  29. return v2 == 456;
  30. }
  31. // 3 Code in file 1 referes to common symbol in file 2.
  32. bool
  33. C1::testcase3()
  34. {
  35. return v3 == 789;
  36. }
  37. // 4 Code in file 1 refers to offset within global data in file 2.
  38. bool
  39. C1::testcase4()
  40. {
  41. return v4[5] == ',';
  42. }
  43. // 5 Code in file 1 refers to offset within common symbol in file 2.
  44. bool
  45. C2::testcase1()
  46. {
  47. return v5[7] == 'w';
  48. }
  49. // 6 Data in file 1 refers to global data in file 2.
  50. int* p6 = &v2;
  51. bool
  52. C2::testcase2()
  53. {
  54. return *p6 == 456;
  55. }
  56. // 7 Data in file 1 refers to common symbol in file 2.
  57. int* p7 = &v3;
  58. bool
  59. C2::testcase3()
  60. {
  61. return *p7 == 789;
  62. }
  63. // 8 Data in file 1 refers to offset within global data in file 2.
  64. char* p8 = &v4[6];
  65. bool
  66. C2::testcase4()
  67. {
  68. return *p8 == ' ';
  69. }
  70. // 9 Data in file 1 refers to offset within common symbol in file 2.
  71. char* p9 = &v5[8];
  72. bool
  73. C3::testcase1()
  74. {
  75. return *p9 == 'o';
  76. }
  77. // 10 Data in file 1 refers to function in file 2.
  78. int (*pfn)() = &f10;
  79. bool
  80. C3::testcase2()
  81. {
  82. return (*pfn)() == 135;
  83. }
  84. // 11 Pass function pointer from file 1 to file 2.
  85. int
  86. f11a()
  87. {
  88. return 246;
  89. }
  90. bool
  91. C3::testcase3()
  92. {
  93. return f11b(&f11a) == 246;
  94. }
  95. // 12 Compare address of function for equality in both files.
  96. bool
  97. t12()
  98. {
  99. return &t12 == c3.f4();
  100. }
  101. // 13 Compare address of inline function for equality in both files.
  102. bool
  103. t13()
  104. {
  105. return &f13i == f13();
  106. }
  107. // 14 Compare string constants in file 1 and file 2.
  108. bool
  109. t14()
  110. {
  111. const char* s1 = TEST_STRING_CONSTANT;
  112. const char* s2 = f14();
  113. while (*s1 != '\0')
  114. if (*s1++ != *s2++)
  115. return false;
  116. return *s2 == '\0';
  117. }
  118. // 15 Compare wide string constants in file 1 and file 2.
  119. bool
  120. t15()
  121. {
  122. const wchar_t* s1 = TEST_WIDE_STRING_CONSTANT;
  123. const wchar_t* s2 = f15();
  124. while (*s1 != '\0')
  125. if (*s1++ != *s2++)
  126. return false;
  127. return *s2 == '\0';
  128. }
  129. // 16 Call a function directly after its address has been taken.
  130. bool
  131. t16()
  132. {
  133. return f10() == 135;
  134. }
  135. // 17 File 1 checks array of string constants defined in file 2.
  136. bool
  137. t17()
  138. {
  139. char c = 'a';
  140. for (int i = 0; i < T17_COUNT; ++i)
  141. {
  142. if (t17data[i][0] != c || t17data[i][1] != '\0')
  143. return false;
  144. ++c;
  145. }
  146. return true;
  147. }
  148. // 18 File 1 checks string constants referenced in code in file 2.
  149. bool
  150. t18()
  151. {
  152. char c = 'a';
  153. for (int i = 0; i < T17_COUNT; ++i)
  154. {
  155. const char* s = f18(i);
  156. if (s[0] != c || s[1] != '\0')
  157. return false;
  158. ++c;
  159. }
  160. return true;
  161. }