mkrf 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. data/CHANGELOG +2 -0
  2. data/MIT-LICENSE +7 -0
  3. data/README +54 -0
  4. data/Rakefile +107 -0
  5. data/lib/mkrf.rb +4 -0
  6. data/lib/mkrf/availability.rb +219 -0
  7. data/lib/mkrf/generator.rb +146 -0
  8. data/test/abstract_unit.rb +4 -0
  9. data/test/fixtures/down_a_directory/header_down_a_directory.h +1 -0
  10. data/test/fixtures/stdmkrf.h +1 -0
  11. data/test/sample_files/libtrivial/Rakefile +31 -0
  12. data/test/sample_files/libtrivial/extconf.rb +3 -0
  13. data/test/sample_files/libtrivial/lib/libtrivial.c +5 -0
  14. data/test/sample_files/libtrivial/lib/libtrivial.o +0 -0
  15. data/test/sample_files/libtrivial/libtrivial_so.bundle +0 -0
  16. data/test/sample_files/libtrivial/mkrf.log +1 -0
  17. data/test/sample_files/libxml-ruby-0.3.8/CHANGELOG +74 -0
  18. data/test/sample_files/libxml-ruby-0.3.8/LICENSE +22 -0
  19. data/test/sample_files/libxml-ruby-0.3.8/README +144 -0
  20. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/cbg.c +76 -0
  21. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/extconf.rb +49 -0
  22. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/libxml.c +86 -0
  23. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/libxml.h +82 -0
  24. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/libxml.rb +107 -0
  25. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/mkrf.log +1 -0
  26. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/old_extconf.rb +95 -0
  27. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attr.c +372 -0
  28. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attr.h +21 -0
  29. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attribute.c +224 -0
  30. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attribute.h +21 -0
  31. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_document.c +1159 -0
  32. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_document.h +27 -0
  33. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_dtd.c +168 -0
  34. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_dtd.h +17 -0
  35. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_input_cbg.c +167 -0
  36. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_input_cbg.h +21 -0
  37. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node.c +2139 -0
  38. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node.h +28 -0
  39. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node_set.c +248 -0
  40. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node_set.h +26 -0
  41. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_ns.c +153 -0
  42. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_ns.h +21 -0
  43. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser.c +1417 -0
  44. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser.h +31 -0
  45. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser_context.c +715 -0
  46. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser_context.h +22 -0
  47. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_sax_parser.c +426 -0
  48. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_sax_parser.h +52 -0
  49. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_schema.c +142 -0
  50. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_schema.h +16 -0
  51. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_tree.c +43 -0
  52. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_tree.h +12 -0
  53. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xinclude.c +20 -0
  54. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xinclude.h +13 -0
  55. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath.c +363 -0
  56. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath.h +24 -0
  57. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath_context.c +125 -0
  58. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath_context.h +24 -0
  59. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer.c +100 -0
  60. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer.h +27 -0
  61. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer_context.c +21 -0
  62. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer_context.h +18 -0
  63. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/sax_parser_callbacks.inc +202 -0
  64. data/test/sample_files/syck-0.55/CHANGELOG +186 -0
  65. data/test/sample_files/syck-0.55/COPYING +54 -0
  66. data/test/sample_files/syck-0.55/Makefile +582 -0
  67. data/test/sample_files/syck-0.55/Makefile.am +5 -0
  68. data/test/sample_files/syck-0.55/Makefile.in +582 -0
  69. data/test/sample_files/syck-0.55/README +105 -0
  70. data/test/sample_files/syck-0.55/README.BYTECODE +484 -0
  71. data/test/sample_files/syck-0.55/README.EXT +444 -0
  72. data/test/sample_files/syck-0.55/RELEASE +123 -0
  73. data/test/sample_files/syck-0.55/TODO +25 -0
  74. data/test/sample_files/syck-0.55/aclocal.m4 +883 -0
  75. data/test/sample_files/syck-0.55/bootstrap +7 -0
  76. data/test/sample_files/syck-0.55/config.h +79 -0
  77. data/test/sample_files/syck-0.55/config.h.in +78 -0
  78. data/test/sample_files/syck-0.55/config.status +1197 -0
  79. data/test/sample_files/syck-0.55/config/README +14 -0
  80. data/test/sample_files/syck-0.55/config/depcomp +529 -0
  81. data/test/sample_files/syck-0.55/config/install-sh +323 -0
  82. data/test/sample_files/syck-0.55/config/missing +357 -0
  83. data/test/sample_files/syck-0.55/configure +6728 -0
  84. data/test/sample_files/syck-0.55/configure.in +36 -0
  85. data/test/sample_files/syck-0.55/ext/ruby/CHANGELOG +303 -0
  86. data/test/sample_files/syck-0.55/ext/ruby/README +400 -0
  87. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/MANIFEST +1 -0
  88. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/bytecode.c +1170 -0
  89. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/emitter.c +1224 -0
  90. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/extconf.rb +10 -0
  91. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/gram.c +1894 -0
  92. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/gram.h +79 -0
  93. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/handler.c +174 -0
  94. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/implicit.c +2989 -0
  95. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/mkrf.log +1 -0
  96. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/node.c +407 -0
  97. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/rubyext.c +2385 -0
  98. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/syck.c +504 -0
  99. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/syck.h +458 -0
  100. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/token.c +2707 -0
  101. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/yaml2byte.c +250 -0
  102. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/yamlbyte.h +170 -0
  103. data/test/sample_files/syck-0.55/ext/ruby/install.rb +1022 -0
  104. data/test/sample_files/syck-0.55/ext/ruby/lib/okay.rb +161 -0
  105. data/test/sample_files/syck-0.55/ext/ruby/lib/okay/news.rb +69 -0
  106. data/test/sample_files/syck-0.55/ext/ruby/lib/okay/rpc.rb +434 -0
  107. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml.rb +436 -0
  108. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/baseemitter.rb +247 -0
  109. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/basenode.rb +216 -0
  110. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/compat.rb +26 -0
  111. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/constants.rb +45 -0
  112. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/dbm.rb +111 -0
  113. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/emitter.rb +107 -0
  114. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/encoding.rb +33 -0
  115. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/error.rb +34 -0
  116. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/rubytypes.rb +438 -0
  117. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/store.rb +29 -0
  118. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/stream.rb +40 -0
  119. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/stringio.rb +83 -0
  120. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/syck.rb +19 -0
  121. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/tag.rb +86 -0
  122. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/types.rb +188 -0
  123. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/yamlnode.rb +54 -0
  124. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/ypath.rb +52 -0
  125. data/test/sample_files/syck-0.55/ext/ruby/lib/yod.rb +1168 -0
  126. data/test/sample_files/syck-0.55/ext/ruby/samples/okayNews-modules.rb +27 -0
  127. data/test/sample_files/syck-0.55/ext/ruby/samples/okayNews-sample.rb +336 -0
  128. data/test/sample_files/syck-0.55/ext/ruby/samples/okayNews-validate.rb +341 -0
  129. data/test/sample_files/syck-0.55/ext/ruby/samples/okayRpc-client.rb +51 -0
  130. data/test/sample_files/syck-0.55/ext/ruby/samples/okayRpc-server.rb +85 -0
  131. data/test/sample_files/syck-0.55/ext/ruby/samples/yaml-sortHashKeys.rb +128 -0
  132. data/test/sample_files/syck-0.55/ext/ruby/tests/basic.rb +1653 -0
  133. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsAnchorAlias.yml +51 -0
  134. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsBasicTests.yml +282 -0
  135. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsBlockMapping.yml +78 -0
  136. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsBlockSequence.yml +0 -0
  137. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsDocumentSeparator.yml +102 -0
  138. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsErrorTests.yml +23 -0
  139. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsFlowCollections.yml +73 -0
  140. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsFoldedScalars.yml +215 -0
  141. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsMapInSeq.yml +0 -0
  142. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsNullsAndEmpties.yml +66 -0
  143. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsRubyTests.yml +182 -0
  144. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsSpecificationExamples.yml +2699 -0
  145. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsTypeTransfers.yml +265 -0
  146. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsYpath.yml +221 -0
  147. data/test/sample_files/syck-0.55/ext/ruby/yts/cookbook.rb +159 -0
  148. data/test/sample_files/syck-0.55/ext/ruby/yts/index.yml +10 -0
  149. data/test/sample_files/syck-0.55/ext/ruby/yts/yts.rb +193 -0
  150. data/test/sample_files/syck-0.55/lib/Makefile +497 -0
  151. data/test/sample_files/syck-0.55/lib/Makefile.am +27 -0
  152. data/test/sample_files/syck-0.55/lib/Makefile.in +497 -0
  153. data/test/sample_files/syck-0.55/lib/bytecode.c +1170 -0
  154. data/test/sample_files/syck-0.55/lib/bytecode.re +525 -0
  155. data/test/sample_files/syck-0.55/lib/emitter.c +1224 -0
  156. data/test/sample_files/syck-0.55/lib/gram.c +1894 -0
  157. data/test/sample_files/syck-0.55/lib/gram.h +79 -0
  158. data/test/sample_files/syck-0.55/lib/gram.output +2005 -0
  159. data/test/sample_files/syck-0.55/lib/gram.y +481 -0
  160. data/test/sample_files/syck-0.55/lib/handler.c +174 -0
  161. data/test/sample_files/syck-0.55/lib/implicit.c +2989 -0
  162. data/test/sample_files/syck-0.55/lib/implicit.re +206 -0
  163. data/test/sample_files/syck-0.55/lib/node.c +407 -0
  164. data/test/sample_files/syck-0.55/lib/syck.c +504 -0
  165. data/test/sample_files/syck-0.55/lib/syck.h +458 -0
  166. data/test/sample_files/syck-0.55/lib/syck_st.c +577 -0
  167. data/test/sample_files/syck-0.55/lib/syck_st.h +46 -0
  168. data/test/sample_files/syck-0.55/lib/token.c +2707 -0
  169. data/test/sample_files/syck-0.55/lib/token.re +1139 -0
  170. data/test/sample_files/syck-0.55/lib/yaml2byte.c +250 -0
  171. data/test/sample_files/syck-0.55/lib/yamlbyte.h +170 -0
  172. data/test/sample_files/syck-0.55/stamp-h1 +1 -0
  173. data/test/sample_files/syck-0.55/tests/Basic.c +141 -0
  174. data/test/sample_files/syck-0.55/tests/CuTest.c +294 -0
  175. data/test/sample_files/syck-0.55/tests/CuTest.h +84 -0
  176. data/test/sample_files/syck-0.55/tests/Emit.c +87 -0
  177. data/test/sample_files/syck-0.55/tests/Makefile +480 -0
  178. data/test/sample_files/syck-0.55/tests/Makefile.am +13 -0
  179. data/test/sample_files/syck-0.55/tests/Makefile.in +480 -0
  180. data/test/sample_files/syck-0.55/tests/Parse.c +208 -0
  181. data/test/sample_files/syck-0.55/tests/YTS.c +2310 -0
  182. data/test/sample_files/syck-0.55/tests/YTS.c.erb +326 -0
  183. data/test/sample_files/syck-0.55/tests/YTS.c.rb +44 -0
  184. data/test/test_availability.rb +68 -0
  185. data/test/test_generator.rb +74 -0
  186. metadata +252 -0
@@ -0,0 +1,294 @@
1
+ #include <assert.h>
2
+ #include <setjmp.h>
3
+ #include <stdlib.h>
4
+ #include <stdio.h>
5
+ #include <string.h>
6
+
7
+ #include "CuTest.h"
8
+
9
+ /*-------------------------------------------------------------------------*
10
+ * CuStr
11
+ *-------------------------------------------------------------------------*/
12
+
13
+ char* CuStrAlloc(int size)
14
+ {
15
+ char* new = (char*) malloc( sizeof(char) * (size) );
16
+ return new;
17
+ }
18
+
19
+ char* CuStrCopy(char* old)
20
+ {
21
+ int len = strlen(old);
22
+ char* new = CuStrAlloc(len + 1);
23
+ strcpy(new, old);
24
+ return new;
25
+ }
26
+
27
+ /*-------------------------------------------------------------------------*
28
+ * CuString
29
+ *-------------------------------------------------------------------------*/
30
+
31
+ void CuStringInit(CuString* str)
32
+ {
33
+ str->length = 0;
34
+ str->size = STRING_MAX;
35
+ str->buffer = (char*) malloc(sizeof(char) * str->size);
36
+ str->buffer[0] = '\0';
37
+ }
38
+
39
+ CuString* CuStringNew(void)
40
+ {
41
+ CuString* str = (CuString*) malloc(sizeof(CuString));
42
+ str->length = 0;
43
+ str->size = STRING_MAX;
44
+ str->buffer = (char*) malloc(sizeof(char) * str->size);
45
+ str->buffer[0] = '\0';
46
+ return str;
47
+ }
48
+
49
+ void CuStringResize(CuString* str, int newSize)
50
+ {
51
+ str->buffer = (char*) realloc(str->buffer, sizeof(char) * newSize);
52
+ str->size = newSize;
53
+ }
54
+
55
+ void CuStringAppend(CuString* str, char* text)
56
+ {
57
+ int length = strlen(text);
58
+ CuStringAppendLen(str, text, length);
59
+ }
60
+
61
+ void CuStringAppendLen(CuString* str, char* text, long length)
62
+ {
63
+ if (str->length + length + 1 >= str->size)
64
+ CuStringResize(str, str->length + length + 1 + STRING_INC);
65
+ str->length += length;
66
+ strcat(str->buffer, text);
67
+ }
68
+
69
+ void CuStringAppendChar(CuString* str, char ch)
70
+ {
71
+ char text[2];
72
+ text[0] = ch;
73
+ text[1] = '\0';
74
+ CuStringAppend(str, text);
75
+ }
76
+
77
+ void CuStringAppendFormat(CuString* str, char* format, ...)
78
+ {
79
+ va_list argp;
80
+ char buf[HUGE_STRING_LEN];
81
+ va_start(argp, format);
82
+ vsprintf(buf, format, argp);
83
+ va_end(argp);
84
+ CuStringAppend(str, buf);
85
+ }
86
+
87
+ void CuStringFree(CuString* str)
88
+ {
89
+ if ( str != NULL )
90
+ {
91
+ free( str->buffer );
92
+ free( str );
93
+ }
94
+ }
95
+
96
+ /*-------------------------------------------------------------------------*
97
+ * CuTest
98
+ *-------------------------------------------------------------------------*/
99
+
100
+ void CuTestInit(CuTest* t, char* name, TestFunction function)
101
+ {
102
+ t->name = CuStrCopy(name);
103
+ t->failed = 0;
104
+ t->ran = 0;
105
+ t->message = NULL;
106
+ t->function = function;
107
+ t->jumpBuf = NULL;
108
+ }
109
+
110
+ CuTest* CuTestNew(char* name, TestFunction function)
111
+ {
112
+ CuTest* tc = CU_ALLOC(CuTest);
113
+ CuTestInit(tc, name, function);
114
+ return tc;
115
+ }
116
+
117
+ void CuTestFree(CuTest* t)
118
+ {
119
+ if ( t != NULL )
120
+ {
121
+ free( t->name );
122
+ free( t );
123
+ }
124
+ }
125
+
126
+ void CuFail(CuTest* tc, char* message)
127
+ {
128
+ tc->failed = 1;
129
+ tc->message = CuStrCopy(message);
130
+ if (tc->jumpBuf != 0) longjmp(*(tc->jumpBuf), 0);
131
+ }
132
+
133
+ void CuAssert(CuTest* tc, char* message, int condition)
134
+ {
135
+ if (condition) return;
136
+ CuFail(tc, message);
137
+ }
138
+
139
+ void CuAssertTrue(CuTest* tc, int condition)
140
+ {
141
+ if (condition) return;
142
+ CuFail(tc, "assert failed");
143
+ }
144
+
145
+ void CuAssertStrEquals(CuTest* tc, char* expected, char* actual)
146
+ {
147
+ CuString* message;
148
+ if (strcmp(expected, actual) == 0) return;
149
+ message = CuStringNew();
150
+ CuStringAppend(message, "expected <");
151
+ CuStringAppend(message, expected);
152
+ CuStringAppend(message, "> but was <");
153
+ CuStringAppend(message, actual);
154
+ CuStringAppend(message, ">");
155
+ CuFail(tc, message->buffer);
156
+ }
157
+
158
+ void CuAssertIntEquals(CuTest* tc, int expected, int actual)
159
+ {
160
+ char buf[STRING_MAX];
161
+ if (expected == actual) return;
162
+ sprintf(buf, "expected <%d> but was <%d>", expected, actual);
163
+ CuFail(tc, buf);
164
+ }
165
+
166
+ void CuAssertPtrEquals(CuTest* tc, void* expected, void* actual)
167
+ {
168
+ char buf[STRING_MAX];
169
+ if (expected == actual) return;
170
+ sprintf(buf, "expected pointer <0x%p> but was <0x%p>", expected, actual);
171
+ CuFail(tc, buf);
172
+ }
173
+
174
+ void CuAssertPtrNotNull(CuTest* tc, void* pointer)
175
+ {
176
+ char buf[STRING_MAX];
177
+ if (pointer != NULL ) return;
178
+ sprintf(buf, "null pointer unexpected");
179
+ CuFail(tc, buf);
180
+ }
181
+
182
+ void CuTestRun(CuTest* tc)
183
+ {
184
+ jmp_buf buf;
185
+ tc->jumpBuf = &buf;
186
+ if (setjmp(buf) == 0)
187
+ {
188
+ tc->ran = 1;
189
+ (tc->function)(tc);
190
+ }
191
+ tc->jumpBuf = 0;
192
+ }
193
+
194
+ /*-------------------------------------------------------------------------*
195
+ * CuSuite
196
+ *-------------------------------------------------------------------------*/
197
+
198
+ void CuSuiteInit(CuSuite* testSuite)
199
+ {
200
+ testSuite->count = 0;
201
+ testSuite->failCount = 0;
202
+ }
203
+
204
+ CuSuite* CuSuiteNew()
205
+ {
206
+ CuSuite* testSuite = CU_ALLOC(CuSuite);
207
+ CuSuiteInit(testSuite);
208
+ return testSuite;
209
+ }
210
+
211
+ void CuSuiteFree(CuSuite* testSuite)
212
+ {
213
+ int i;
214
+ for (i = 0 ; i < testSuite->count ; ++i)
215
+ {
216
+ CuTestFree( testSuite->list[i] );
217
+ }
218
+ free( testSuite );
219
+ }
220
+
221
+ void CuSuiteAdd(CuSuite* testSuite, CuTest *testCase)
222
+ {
223
+ assert(testSuite->count < MAX_TEST_CASES);
224
+ testSuite->list[testSuite->count] = testCase;
225
+ testSuite->count++;
226
+ }
227
+
228
+ void CuSuiteAddSuite(CuSuite* testSuite, CuSuite* testSuite2)
229
+ {
230
+ int i;
231
+ for (i = 0 ; i < testSuite2->count ; ++i)
232
+ {
233
+ CuTest* testCase = testSuite2->list[i];
234
+ CuSuiteAdd(testSuite, testCase);
235
+ }
236
+ }
237
+
238
+ void CuSuiteRun(CuSuite* testSuite)
239
+ {
240
+ int i;
241
+ for (i = 0 ; i < testSuite->count ; ++i)
242
+ {
243
+ CuTest* testCase = testSuite->list[i];
244
+ CuTestRun(testCase);
245
+ if (testCase->failed) { testSuite->failCount += 1; }
246
+ }
247
+ }
248
+
249
+ void CuSuiteSummary(CuSuite* testSuite, CuString* summary)
250
+ {
251
+ int i;
252
+ for (i = 0 ; i < testSuite->count ; ++i)
253
+ {
254
+ CuTest* testCase = testSuite->list[i];
255
+ CuStringAppend(summary, testCase->failed ? "F" : ".");
256
+ }
257
+ CuStringAppend(summary, "\n\n");
258
+ }
259
+
260
+ void CuSuiteDetails(CuSuite* testSuite, CuString* details)
261
+ {
262
+ int i;
263
+ int failCount = 0;
264
+
265
+ if (testSuite->failCount == 0)
266
+ {
267
+ int passCount = testSuite->count - testSuite->failCount;
268
+ char* testWord = passCount == 1 ? "test" : "tests";
269
+ CuStringAppendFormat(details, "OK (%d %s)\n", passCount, testWord);
270
+ }
271
+ else
272
+ {
273
+ if (testSuite->failCount == 1)
274
+ CuStringAppend(details, "There was 1 failure:\n");
275
+ else
276
+ CuStringAppendFormat(details, "There were %d failures:\n", testSuite->failCount);
277
+
278
+ for (i = 0 ; i < testSuite->count ; ++i)
279
+ {
280
+ CuTest* testCase = testSuite->list[i];
281
+ if (testCase->failed)
282
+ {
283
+ failCount++;
284
+ CuStringAppendFormat(details, "%d) %s: %s\n",
285
+ failCount, testCase->name, testCase->message);
286
+ }
287
+ }
288
+ CuStringAppend(details, "\n!!!FAILURES!!!\n");
289
+
290
+ CuStringAppendFormat(details, "Runs: %d ", testSuite->count);
291
+ CuStringAppendFormat(details, "Passes: %d ", testSuite->count - testSuite->failCount);
292
+ CuStringAppendFormat(details, "Fails: %d\n", testSuite->failCount);
293
+ }
294
+ }
@@ -0,0 +1,84 @@
1
+ #ifndef CU_TEST_H
2
+ #define CU_TEST_H
3
+
4
+ #include <setjmp.h>
5
+ #include <stdarg.h>
6
+
7
+ /* CuString */
8
+
9
+ char* CuStrAlloc(int size);
10
+ char* CuStrCopy(char* old);
11
+
12
+ #define CU_ALLOC(TYPE) ((TYPE*) malloc(sizeof(TYPE)))
13
+
14
+ #define HUGE_STRING_LEN 8192
15
+ #define STRING_MAX 256
16
+ #define STRING_INC 256
17
+
18
+ typedef struct
19
+ {
20
+ int length;
21
+ int size;
22
+ char* buffer;
23
+ } CuString;
24
+
25
+ void CuStringInit(CuString* str);
26
+ CuString* CuStringNew(void);
27
+ void CuStringRead(CuString* str, char* path);
28
+ void CuStringAppend(CuString* str, char* text);
29
+ void CuStringAppendLen(CuString* str, char* text, long length);
30
+ void CuStringAppendChar(CuString* str, char ch);
31
+ void CuStringAppendFormat(CuString* str, char* format, ...);
32
+ void CuStringResize(CuString* str, int newSize);
33
+
34
+ /* CuTest */
35
+
36
+ typedef struct CuTest CuTest;
37
+
38
+ typedef void (*TestFunction)(CuTest *);
39
+
40
+ struct CuTest
41
+ {
42
+ char* name;
43
+ TestFunction function;
44
+ int failed;
45
+ int ran;
46
+ char* message;
47
+ jmp_buf *jumpBuf;
48
+ };
49
+
50
+ void CuTestInit(CuTest* t, char* name, TestFunction function);
51
+ CuTest* CuTestNew(char* name, TestFunction function);
52
+ void CuFail(CuTest* tc, char* message);
53
+ void CuAssert(CuTest* tc, char* message, int condition);
54
+ void CuAssertTrue(CuTest* tc, int condition);
55
+ void CuAssertStrEquals(CuTest* tc, char* expected, char* actual);
56
+ void CuAssertIntEquals(CuTest* tc, int expected, int actual);
57
+ void CuAssertPtrEquals(CuTest* tc, void* expected, void* actual);
58
+ void CuAssertPtrNotNull(CuTest* tc, void* pointer);
59
+ void CuTestRun(CuTest* tc);
60
+
61
+ /* CuSuite */
62
+
63
+ #define MAX_TEST_CASES 1024
64
+
65
+ #define SUITE_ADD_TEST(SUITE,TEST) CuSuiteAdd(SUITE, CuTestNew(#TEST, TEST))
66
+
67
+ typedef struct
68
+ {
69
+ int count;
70
+ CuTest* list[MAX_TEST_CASES];
71
+ int failCount;
72
+
73
+ } CuSuite;
74
+
75
+
76
+ void CuSuiteInit(CuSuite* testSuite);
77
+ CuSuite* CuSuiteNew();
78
+ void CuSuiteAdd(CuSuite* testSuite, CuTest *testCase);
79
+ void CuSuiteAddSuite(CuSuite* testSuite, CuSuite* testSuite2);
80
+ void CuSuiteRun(CuSuite* testSuite);
81
+ void CuSuiteSummary(CuSuite* testSuite, CuString* summary);
82
+ void CuSuiteDetails(CuSuite* testSuite, CuString* details);
83
+
84
+ #endif /* CU_TEST_H */
@@ -0,0 +1,87 @@
1
+ //
2
+ // Emit.c
3
+ //
4
+ // $Author: why $
5
+ // $Date: 2005/01/06 07:23:51 $
6
+ //
7
+ // Copyright (C) 2003 why the lucky stiff
8
+ //
9
+
10
+ #include <string.h>
11
+ #include "syck.h"
12
+ #include "CuTest.h"
13
+
14
+ //
15
+ // 1. Test the buffering -- print 10 bytes at a time
16
+ //
17
+ void
18
+ TestSyckEmit_Output( SyckEmitter *e, char *str, long len )
19
+ {
20
+ // char *tmp = syck_strndup( str, len );
21
+ // printf( "OUT: %s [%d]\n", tmp, len );
22
+ // S_FREE( tmp );
23
+ }
24
+
25
+ void
26
+ TestSyckEmit( CuTest *tc )
27
+ {
28
+ SyckEmitter *emitter;
29
+ char *tmp;
30
+ int len = 0;
31
+
32
+ emitter = syck_new_emitter();
33
+ emitter->bufsize = 10;
34
+ emitter->output_handler = TestSyckEmit_Output;
35
+
36
+ syck_emitter_write( emitter, "Test [1]", 8 );
37
+ syck_emitter_write( emitter, ".", 1 );
38
+ syck_emitter_write( emitter, "Test [2]", 8 );
39
+ syck_emitter_write( emitter, ".", 1 );
40
+ syck_emitter_write( emitter, "Test [3]", 8 );
41
+ syck_emitter_write( emitter, ".", 1 );
42
+ syck_emitter_write( emitter, "Test [4]", 8 );
43
+ syck_emitter_write( emitter, ".", 1 );
44
+ syck_emitter_write( emitter, "END!", 4 );
45
+
46
+ syck_free_emitter( emitter );
47
+ }
48
+
49
+ /*
50
+ * Ensure that our base64 encoder can do some basic
51
+ * binary encoding.
52
+ */
53
+ void TestBase64Encode( CuTest *tc )
54
+ {
55
+ char gif[] = "GIF89a\f\000\f\000\204\000\000\377\377\367\365\365\356\351\351\345fff\000\000\000\347\347\347^^^\363\363\355\216\216\216\340\340\340\237\237\237\223\223\223\247\247\247\236\236\236iiiccc\243\243\243\204\204\204\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371!\376\016Made with GIMP\000,\000\000\000\000\f\000\f\000\000\005, \216\2010\236\343@\024\350i\020\304\321\212\010\034\317\200M$z\357\3770\205p\270\2601f\r\e\316\001\303\001\036\020' \202\n\001\000;";
56
+ char *enc = syck_base64enc( gif, 185 );
57
+ CuAssertStrEquals( tc, enc, "R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLCAgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs=\n" );
58
+ S_FREE( enc );
59
+ }
60
+
61
+ CuSuite *
62
+ SyckGetSuite()
63
+ {
64
+ CuSuite *suite = CuSuiteNew();
65
+ SUITE_ADD_TEST( suite, TestSyckEmit );
66
+ SUITE_ADD_TEST( suite, TestBase64Encode );
67
+ return suite;
68
+ }
69
+
70
+ int main(void)
71
+ {
72
+ CuString *output = CuStringNew();
73
+ CuSuite* suite = SyckGetSuite();
74
+ int count;
75
+
76
+ CuSuiteRun(suite);
77
+ CuSuiteSummary(suite, output);
78
+ CuSuiteDetails(suite, output);
79
+
80
+ printf("%s\n", output->buffer);
81
+ count = suite->failCount;
82
+
83
+ CuStringFree( output );
84
+ CuSuiteFree( suite );
85
+
86
+ return count;
87
+ }