[NEW] Gestalts for silverlight + popular JS libs
[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_all'),
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'),
265       Base.new(:platform, 'moblin_all'),
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'),
280       Base.new(:platform, 'moblin_all'),
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_all'),
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_jasper_jr
467                 make = SourceFile.new("foo.java", :contents => <<-INLINE_JAVA
468       public class Employee implements Serializable {
469         private net.sf.jasperreports.report myReport;
470       }
471                 INLINE_JAVA
472     )
473                 expected_gestalts = [
474       Base.new(:platform, 'jasper_jr'),
475       Base.new(:platform, 'Java'),
476                 ]
477                 assert_equal expected_gestalts.sort, make.gestalts.sort
478   end
479
480   def test_jasper_jr_pom
481                 make = SourceFile.new("pom.xml", :contents => <<-INLINE_POM
482         <project>
483           <groupId>dzrealms</groupId>
484           <artifactId>HelloWorld</artifactId>
485           <version>1.0</version>
486           <dependencies>
487             <dependency>
488               <groupId>jgoodies</groupId>
489               <artifactId>plastic</artifactId>
490               <version>1.2.0</version>
491             </dependency>
492             <dependency>
493               <groupId>log4j</groupId>
494               <artifactId>log4j</artifactId>
495               <version>1.2.8</version>
496             </dependency>
497             <dependency>
498               <groupId>jasperreports</groupId>
499               <artifactId>jasperreports</artifactId>
500               <version>2.0.5</version>
501             </dependency>
502           </dependencies>
503           <build>
504             <sourceDirectory>src/main/java</sourceDirectory>
505             <unitTestSourceDirectory>src/test/java</unitTestSourceDirectory>
506             <unitTest>
507               <includes>
508                 <include>**/*Test.java</include>
509               </includes>
510             </unitTest>
511           </build>
512         </project>
513     INLINE_POM
514     )
515                 expected_gestalts = [
516       Base.new(:platform, 'jasper_jr'),
517                 ]
518                 assert_equal expected_gestalts.sort, make.gestalts.sort
519   end
520
521   def test_jasper_jsce
522                 make = SourceFile.new("foo.java", :contents => <<-INLINE_JAVA
523       public class Employee implements Serializable {
524         private com.jaspersoft.jasperserver;
525       }
526                 INLINE_JAVA
527     )
528                 expected_gestalts = [
529       Base.new(:platform, 'Java'),
530       Base.new(:platform, 'jasper_jsce')
531                 ]
532                 assert_equal expected_gestalts.sort, make.gestalts.sort
533   end
534
535   def test_jasper_ji
536                 make = SourceFile.new("foo.java", :contents => <<-INLINE_JAVA
537       public class Employee implements Serializable {
538         private com.jaspersoft.ji;
539       }
540                 INLINE_JAVA
541     )
542                 expected_gestalts = [
543       Base.new(:platform, 'Java'),
544       Base.new(:platform, 'jasper_ji')
545                 ]
546                 assert_equal expected_gestalts.sort, make.gestalts.sort
547   end
548
549         def test_flash
550                 as = SourceFile.new("sample.as", :contents => 'greet.text = "Hello, world";')
551                 expected_gestalts = [ Base.new(:platform, "flash") ]
552                 assert_equal expected_gestalts.sort, as.gestalts.sort
553         end
554
555         def test_flex
556                 as = SourceFile.new("sample.mxml", :contents => <<-MXML
557                         <?xml version="1.0" encoding="utf-8"?>
558                         <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"></mx:Application>
559                 MXML
560                 )
561                 expected_gestalts = [ Base.new(:platform, 'flex') ]
562                 assert_equal expected_gestalts.sort, as.gestalts.sort
563         end
564 end