[CHANGE] Downcase all platform names
[ohcount] / test / unit / ruby / gestalt / definitions_test.rb
1 require 'test/unit'
2 require File.dirname(__FILE__) + '/../../../../ruby/gestalt'
3
4 include Ohcount
5 include Ohcount::Gestalt
6
7 class DefinitionsTest < Ohcount::Test
8
9         def test_zend_framework
10                 assert_gestalts 'zend_framework', [
11       Base.new(:platform,'php'),
12       Base.new(:platform,'zendframework'),
13                         Base.new(:platform,'scripting')
14     ]
15         end
16
17         def test_php
18                 assert_gestalts 'php', [
19       Base.new(:platform,'php'),
20                         Base.new(:platform,'scripting')
21     ]
22         end
23
24         def test_wx_widgets
25                 assert_gestalts 'wx_widgets', [
26       Base.new(:platform,'wxwidgets'),
27       Base.new(:platform, 'native_code')
28     ]
29         end
30
31         def test_eclipse_platform
32                 assert_gestalts 'eclipse_platform', [
33       Base.new(:platform,'java'),
34       Base.new(:platform,'eclipseplatform'),
35       Base.new(:java_import,"java.text.SimpleDateFormat"),
36       Base.new(:java_import,"java.util.Map"),
37       Base.new(:java_import,"org.eclipse.core")
38     ]
39         end
40
41         def test_win32_not_enough
42                 assert_gestalts 'win32_not_enough', [
43       Base.new(:platform, 'native_code')
44                 ]
45         end
46
47         def test_win32_enough
48                 assert_gestalts 'win32_enough', [
49       Base.new(:platform, 'win32'),
50       Base.new(:platform, 'native_code')
51     ]
52         end
53
54         def test_wpf
55                 assert_gestalts 'wpf', [
56       Base.new(:platform, 'wpf')
57     ]
58         end
59
60         def test_asp_net
61                 assert_gestalts 'asp_net', [
62       Base.new(:platform, 'asp_net')
63     ]
64         end
65
66         def test_ruby_just_enough
67                 assert_gestalts 'ruby_just_enough', [
68       Base.new(:platform, 'ruby'),
69       Base.new(:platform, 'scripting'),
70       Base.new(:platform, 'native_code'),
71     ]
72         end
73
74         def test_ruby_not_enough
75                 assert_gestalts 'ruby_not_enough', [
76                         Base.new(:platform, 'native_code')
77                 ]
78         end
79
80         def test_cakephp
81                 assert_gestalts 'cakephp', [
82       Base.new(:platform, 'php'),
83       Base.new(:platform, 'cakephp'),
84       Base.new(:platform, 'scripting'),
85     ]
86         end
87
88         def test_symfony
89                 assert_platform('symfony', :php, :symfony, :scripting)
90         end
91
92         def test_pear
93                 assert_platform('pear', :php, :pear, :scripting)
94         end
95
96         def test_moodle
97                 assert_platform('moodle', :php, :moodle, :scripting)
98         end
99
100         def test_spring_framework
101                 assert_gestalts 'spring_framework', [
102       Base.new(:platform, 'java'),
103       Base.new(:platform, 'springframework'),
104       Base.new(:java_jar, 'spring.jar'),
105     ]
106         end
107
108         def test_rails
109                 assert_platform('rails', :ruby, :rails, :scripting)
110         end
111
112         def test_jquery
113                 assert_platform('jquery', :javascript, :jquery, :scripting)
114         end
115
116         def test_dojo
117                 h = SourceFile.new("sample.html", :contents => '<SCRIPT TYPE="text/javascript" SRC="http://ajax.googleapis.com/ajax/libs/dojo/1.3/dojo/dojo.xd.js"></SCRIPT>')
118                 expected_gestalts = [ Base.new(:platform, "dojo") ]
119                 assert_equal expected_gestalts.sort, h.gestalts.sort
120         end
121
122         def test_yui
123                 h = SourceFile.new("sample.html", :contents => '<script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/build/yahoo/yahoo-min.js" ></script>')
124                 expected_gestalts = [ Base.new(:platform, "yui") ]
125                 assert_equal expected_gestalts.sort, h.gestalts.sort
126         end
127
128         def test_python
129                 assert_platform('python', :python, :scripting)
130         end
131
132         def test_mac
133                 assert_platform('mac', :mac, :native_code)
134         end
135
136         def test_plist
137                 assert_platform('plist', :mac)
138         end
139
140         def test_posix
141                 assert_platform('posix', :posix, :native_code)
142         end
143
144         def test_x_windows
145                 assert_platform('xwindows', :xwindows, :native_code)
146         end
147
148         def test_kde
149                 assert_platform('kde', :kde, :native_code)
150         end
151
152         def test_msdos
153                 assert_platform('msdos', :msdos, :native_code)
154         end
155
156         def test_gtk
157                 assert_platform('gtk', :gtk, :native_code)
158         end
159
160         def test_drupal
161                 assert_platform('drupal', :php, :drupal, :scripting)
162         end
163
164         def test_vs_1
165                 assert_tool('vs_1', :visualstudio)
166         end
167
168         def test_eclipse
169                 assert_tool('eclipse', :eclipse)
170         end
171
172         def test_netbeans
173                 assert_tool('netbeans', :netbeans)
174         end
175
176         def test_java_imports_from_java_file
177     java = SourceFile.new("foo.java", :contents => <<-INLINE_C
178       import com.foo;
179       import net.ohloh;
180       import com.foo;
181                         // import dont.import.this;
182       INLINE_C
183     )
184
185     expected_gestalts = [
186       Base.new(:java_import, 'com.foo', 2),
187       Base.new(:java_import, 'net.ohloh'),
188       Base.new(:platform,    'java'),
189     ]
190
191     assert_equal expected_gestalts.sort, java.gestalts.sort
192         end
193
194         def test_arm
195     asm = SourceFile.new("foo.S", :contents => <<-INLINE_ASM
196                         orrs 3, eax
197       INLINE_ASM
198     )
199
200                 expected_gestalts = [
201                         Base.new(:platform, 'arm')
202                 ]
203
204                 assert_equal expected_gestalts.sort, asm.gestalts.sort
205         end
206
207         def test_arm_from_c_keywords
208                 c = SourceFile.new("foo.c", :contents => <<-INLINE_C
209       #define __arm__
210                 INLINE_C
211     )
212                 expected_gestalts = [
213       Base.new(:platform, 'arm'),
214       Base.new(:platform, 'native_code')
215                 ]
216                 assert_equal expected_gestalts, c.gestalts
217         end
218
219         def test_arm_neon
220     asm = SourceFile.new("foo.S", :contents => <<-INLINE_ASM
221                         vmov u8, s
222       INLINE_ASM
223     )
224
225     expected_gestalts = [
226       Base.new(:platform, 'arm'),
227       Base.new(:platform, 'arm_neon')
228     ]
229
230     assert_equal expected_gestalts.sort, asm.gestalts.sort
231         end
232
233         def test_imports_from_java_file
234     jar = SourceFile.new("foo/foo.jar", :contents => '')
235
236     expected_gestalts = [
237       Base.new(:java_jar, 'foo.jar'),
238     ]
239
240     assert_equal expected_gestalts.sort, jar.gestalts.sort
241         end
242
243         def test_moblin_clutter
244                 c = SourceFile.new("foo.c", :contents => <<-INLINE_C
245                           clutter_actor_queue_redraw (CLUTTER_ACTOR(label));
246                         INLINE_C
247                 )
248     expected_gestalts = [
249       Base.new(:platform, 'clutter'),
250       Base.new(:platform, 'moblin'),
251       Base.new(:platform, 'mid_combined'),
252       Base.new(:platform, 'native_code')
253     ]
254
255     assert_equal expected_gestalts.sort, c.gestalts.sort
256         end
257
258         def test_moblin_by_filename
259                 c = SourceFile.new("moblin-netbook-system-tray.h", :contents => <<-INLINE_PERL
260                                 #include "foo"
261                         INLINE_PERL
262                 )
263     expected_gestalts = [
264       Base.new(:platform, 'moblin_misc'),
265       Base.new(:platform, 'moblin'),
266       Base.new(:platform, 'mid_combined'),
267       Base.new(:platform, 'native_code')
268     ]
269
270     assert_equal expected_gestalts.sort, c.gestalts.sort
271         end
272
273         def test_moblin_by_keyword
274                 c = SourceFile.new("foo.c", :contents => <<-INLINE_PERL
275                                 proxy = dbus_g_proxy_new_for_name (conn, "org.moblin.connman",
276                         INLINE_PERL
277                 )
278     expected_gestalts = [
279       Base.new(:platform, 'moblin_misc'),
280       Base.new(:platform, 'moblin'),
281       Base.new(:platform, 'mid_combined'),
282       Base.new(:platform, 'native_code')
283     ]
284
285     assert_equal expected_gestalts.sort, c.gestalts.sort
286         end
287
288         def test_nbtk
289                 c = SourceFile.new("foo.c", :contents => <<-INLINE_C
290                                 button = nbtk_button_new_with_label ("Back");
291                         INLINE_C
292                 )
293     expected_gestalts = [
294       Base.new(:platform, 'nbtk'),
295                         Base.new(:platform, 'mid_combined'),
296       Base.new(:platform, 'moblin'),
297       Base.new(:platform, 'native_code')
298     ]
299
300     assert_equal expected_gestalts.sort, c.gestalts.sort
301         end
302
303
304         def test_android
305     java = SourceFile.new("foo.java", :contents => <<-INLINE_C
306                         import android.app.Activity;
307                         // import dont.import.this;
308       INLINE_C
309     )
310
311     expected_gestalts = [
312       Base.new(:java_import, 'android.app.Activity'),
313       Base.new(:platform,    'java'),
314       Base.new(:platform,    'android'),
315       Base.new(:platform,    'mid_combined')
316     ]
317
318     assert_equal expected_gestalts.sort, java.gestalts.sort
319         end
320
321         def test_iphone
322     objective_c = SourceFile.new("foo.m", :contents => <<-OBJECTIVE_C
323                          #import <Foundation/Foundation.h>
324                          #import <UIKit/UIKit.h>
325                          #import "WhackABugApp.h"
326
327                          int main(int argc, char *argv[]) {
328                                  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
329                                  int ret = UIApplicationMain(argc, argv, [WhackABugApp class]);
330                                  [pool release];
331                                  return ret;
332                          }
333       OBJECTIVE_C
334     )
335
336     expected_gestalts = [
337       Base.new(:platform, 'iphone'),
338       Base.new(:platform, 'mid_combined')
339     ]
340
341     assert_equal expected_gestalts.sort, objective_c.gestalts.sort
342         end
343
344         def test_hildon
345                 c = SourceFile.new("foo.c", :contents => <<-INLINE_C
346                                 HildonWindow *window;
347                         INLINE_C
348                 )
349     expected_gestalts = [
350       Base.new(:platform, 'hildon'),
351       Base.new(:platform, 'maemo'),
352       Base.new(:platform, 'native_code'),
353       Base.new(:platform, 'mid_combined')
354     ]
355
356     assert_equal expected_gestalts.sort, c.gestalts.sort
357         end
358
359         def test_atom_linux
360                 make = SourceFile.new("makefile", :contents => <<-INLINE_MAKEFILE
361                         COMPILE_FLAGS=/QxL
362                 INLINE_MAKEFILE
363     )
364                 expected_gestalts = [
365       Base.new(:platform, 'xl_flag'),
366       Base.new(:platform, 'atom')
367                 ]
368                 assert_equal expected_gestalts.sort, make.gestalts.sort
369         end
370
371         def test_atom_windows
372                 make = SourceFile.new("makefile", :contents => <<-INLINE_MAKEFILE
373                         CCFLAGS = -xL
374                 INLINE_MAKEFILE
375     )
376                 expected_gestalts = [
377       Base.new(:platform, 'xl_flag'),
378       Base.new(:platform, 'atom')
379                 ]
380                 assert_equal expected_gestalts.sort, make.gestalts.sort
381         end
382
383         def test_not_atom_windows
384                 make = SourceFile.new("makefile", :contents => <<-INLINE_MAKEFILE
385                         CCFLAGS = -xLo
386                 INLINE_MAKEFILE
387     )
388                 expected_gestalts = []
389                 assert_equal expected_gestalts.sort, make.gestalts.sort
390         end
391
392         def test_atom_sse3
393                 make = SourceFile.new("makefile", :contents => <<-INLINE_MAKEFILE
394                         COMPILE_FLAGS=-xSSE3_ATOM_FLAG
395                 INLINE_MAKEFILE
396     )
397                 expected_gestalts = [
398       Base.new(:platform, 'sse3_atom_flag'),
399       Base.new(:platform, 'atom')
400                 ]
401                 assert_equal expected_gestalts.sort, make.gestalts.sort
402         end
403
404         def test_intel_compiler
405
406                 make = SourceFile.new("Makefile", :contents => <<-INLINE_MAKEFILE
407                         CC = icc
408                 INLINE_MAKEFILE
409     )
410                 expected_gestalts = [
411       Base.new(:platform, 'intel_compiler'),
412                 ]
413                 assert_equal expected_gestalts.sort, make.gestalts.sort
414         end
415
416         def test_opensso
417                 java = SourceFile.new("foo.java", :contents => <<-INLINE_JAVA
418 import com.sun.identity.authentication;
419                         INLINE_JAVA
420                 )
421     expected_gestalts = [
422       Base.new(:platform, 'java'),
423       Base.new(:platform, 'opensso'),
424       Base.new(:java_import, 'com.sun.identity')
425     ]
426
427     assert_equal expected_gestalts.sort, java.gestalts.sort
428         end
429
430         def test_windows_ce
431                 csharp = SourceFile.new("bam.cs", :contents => <<-INLINE_CSHARP
432                                 using System;
433                                 using Microsoft.WindowsMobile.DirectX;
434                         INLINE_CSHARP
435                 )
436     expected_gestalts = [
437       Base.new(:platform, 'windows_ce_incomplete'),
438       Base.new(:platform, 'dot_net'),
439     ]
440
441                 assert_equal expected_gestalts.sort, csharp.gestalts.sort
442         end
443
444         def test_gcc
445                 make = SourceFile.new("Makefile", :contents => <<-INLINE_MAKEFILE
446                         CC = gcc
447                 INLINE_MAKEFILE
448     )
449                 expected_gestalts = [
450       Base.new(:platform, 'gcc'),
451                 ]
452                 assert_equal expected_gestalts.sort, make.gestalts.sort
453         end
454
455         def test_native_code
456                 c = SourceFile.new("foo.c", :contents => <<-INLINE_C
457                         int *pcode = NULL;
458                 INLINE_C
459     )
460                 expected_gestalts = [
461       Base.new(:platform, 'native_code'),
462                 ]
463                 assert_equal expected_gestalts.sort, c.gestalts.sort
464         end
465
466         def test_flash
467                 as = SourceFile.new("sample.as", :contents => 'greet.text = "Hello, world";')
468                 expected_gestalts = [ Base.new(:platform, "flash") ]
469                 assert_equal expected_gestalts.sort, as.gestalts.sort
470         end
471
472         def test_flex
473                 as = SourceFile.new("sample.mxml", :contents => <<-MXML
474                         <?xml version="1.0" encoding="utf-8"?>
475                         <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"></mx:Application>
476                 MXML
477                 )
478                 expected_gestalts = [ Base.new(:platform, 'flex') ]
479                 assert_equal expected_gestalts.sort, as.gestalts.sort
480         end
481 end