2 require File.dirname(__FILE__) + '/../../../../ruby/gestalt'
5 include Ohcount::Gestalt
7 class DefinitionsTest < Ohcount::Test
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')
18 assert_gestalts 'php', [
19 Base.new(:platform,'php'),
20 Base.new(:platform,'scripting')
25 assert_gestalts 'wx_widgets', [
26 Base.new(:platform,'wxwidgets'),
27 Base.new(:platform, 'native_code')
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")
41 def test_win32_not_enough
42 assert_gestalts 'win32_not_enough', [
43 Base.new(:platform, 'native_code')
48 assert_gestalts 'win32_enough', [
49 Base.new(:platform, 'win32'),
50 Base.new(:platform, 'native_code')
55 assert_gestalts 'wpf', [
56 Base.new(:platform, 'wpf')
61 assert_gestalts 'asp_net', [
62 Base.new(:platform, 'asp_net')
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'),
74 def test_ruby_not_enough
75 assert_gestalts 'ruby_not_enough', [
76 Base.new(:platform, 'native_code')
81 assert_gestalts 'cakephp', [
82 Base.new(:platform, 'php'),
83 Base.new(:platform, 'cakephp'),
84 Base.new(:platform, 'scripting'),
89 assert_platform('symfony', :php, :symfony, :scripting)
93 assert_platform('pear', :php, :pear, :scripting)
97 assert_platform('moodle', :php, :moodle, :scripting)
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'),
109 assert_platform('rails', :ruby, :rails, :scripting)
113 assert_platform('jquery', :javascript, :jquery, :scripting)
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
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
129 assert_platform('python', :python, :scripting)
133 assert_platform('mac', :mac, :native_code)
137 assert_platform('plist', :mac)
141 assert_platform('posix', :posix, :native_code)
145 assert_platform('xwindows', :xwindows, :native_code)
149 assert_platform('kde', :kde, :native_code)
153 assert_platform('msdos', :msdos, :native_code)
157 assert_platform('gtk', :gtk, :native_code)
161 assert_platform('drupal', :php, :drupal, :scripting)
165 assert_tool('vs_1', :visualstudio)
169 assert_tool('eclipse', :eclipse)
173 assert_tool('netbeans', :netbeans)
176 def test_java_imports_from_java_file
177 java = SourceFile.new("foo.java", :contents => <<-INLINE_C
181 // import dont.import.this;
185 expected_gestalts = [
186 Base.new(:java_import, 'com.foo', 2),
187 Base.new(:java_import, 'net.ohloh'),
188 Base.new(:platform, 'java'),
191 assert_equal expected_gestalts.sort, java.gestalts.sort
195 asm = SourceFile.new("foo.S", :contents => <<-INLINE_ASM
200 expected_gestalts = [
201 Base.new(:platform, 'arm')
204 assert_equal expected_gestalts.sort, asm.gestalts.sort
207 def test_arm_from_c_keywords
208 c = SourceFile.new("foo.c", :contents => <<-INLINE_C
212 expected_gestalts = [
213 Base.new(:platform, 'arm'),
214 Base.new(:platform, 'native_code')
216 assert_equal expected_gestalts, c.gestalts
220 asm = SourceFile.new("foo.S", :contents => <<-INLINE_ASM
225 expected_gestalts = [
226 Base.new(:platform, 'arm'),
227 Base.new(:platform, 'arm_neon')
230 assert_equal expected_gestalts.sort, asm.gestalts.sort
233 def test_imports_from_java_file
234 jar = SourceFile.new("foo/foo.jar", :contents => '')
236 expected_gestalts = [
237 Base.new(:java_jar, 'foo.jar'),
240 assert_equal expected_gestalts.sort, jar.gestalts.sort
243 def test_moblin_clutter
244 c = SourceFile.new("foo.c", :contents => <<-INLINE_C
245 clutter_actor_queue_redraw (CLUTTER_ACTOR(label));
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')
255 assert_equal expected_gestalts.sort, c.gestalts.sort
258 def test_moblin_by_filename
259 c = SourceFile.new("moblin-netbook-system-tray.h", :contents => <<-INLINE_PERL
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')
270 assert_equal expected_gestalts.sort, c.gestalts.sort
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",
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')
285 assert_equal expected_gestalts.sort, c.gestalts.sort
289 c = SourceFile.new("foo.c", :contents => <<-INLINE_C
290 button = nbtk_button_new_with_label ("Back");
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')
300 assert_equal expected_gestalts.sort, c.gestalts.sort
305 java = SourceFile.new("foo.java", :contents => <<-INLINE_C
306 import android.app.Activity;
307 // import dont.import.this;
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')
318 assert_equal expected_gestalts.sort, java.gestalts.sort
322 objective_c = SourceFile.new("foo.m", :contents => <<-OBJECTIVE_C
323 #import <Foundation/Foundation.h>
324 #import <UIKit/UIKit.h>
325 #import "WhackABugApp.h"
327 int main(int argc, char *argv[]) {
328 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
329 int ret = UIApplicationMain(argc, argv, [WhackABugApp class]);
336 expected_gestalts = [
337 Base.new(:platform, 'iphone'),
338 Base.new(:platform, 'mid_combined')
341 assert_equal expected_gestalts.sort, objective_c.gestalts.sort
345 c = SourceFile.new("foo.c", :contents => <<-INLINE_C
346 HildonWindow *window;
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')
356 assert_equal expected_gestalts.sort, c.gestalts.sort
360 make = SourceFile.new("makefile", :contents => <<-INLINE_MAKEFILE
364 expected_gestalts = [
365 Base.new(:platform, 'xl_flag'),
366 Base.new(:platform, 'atom')
368 assert_equal expected_gestalts.sort, make.gestalts.sort
371 def test_atom_windows
372 make = SourceFile.new("makefile", :contents => <<-INLINE_MAKEFILE
376 expected_gestalts = [
377 Base.new(:platform, 'xl_flag'),
378 Base.new(:platform, 'atom')
380 assert_equal expected_gestalts.sort, make.gestalts.sort
383 def test_not_atom_windows
384 make = SourceFile.new("makefile", :contents => <<-INLINE_MAKEFILE
388 expected_gestalts = []
389 assert_equal expected_gestalts.sort, make.gestalts.sort
393 make = SourceFile.new("makefile", :contents => <<-INLINE_MAKEFILE
394 COMPILE_FLAGS=-xSSE3_ATOM_FLAG
397 expected_gestalts = [
398 Base.new(:platform, 'sse3_atom_flag'),
399 Base.new(:platform, 'atom')
401 assert_equal expected_gestalts.sort, make.gestalts.sort
404 def test_intel_compiler
406 make = SourceFile.new("Makefile", :contents => <<-INLINE_MAKEFILE
410 expected_gestalts = [
411 Base.new(:platform, 'intel_compiler'),
413 assert_equal expected_gestalts.sort, make.gestalts.sort
417 java = SourceFile.new("foo.java", :contents => <<-INLINE_JAVA
418 import com.sun.identity.authentication;
421 expected_gestalts = [
422 Base.new(:platform, 'java'),
423 Base.new(:platform, 'opensso'),
424 Base.new(:java_import, 'com.sun.identity')
427 assert_equal expected_gestalts.sort, java.gestalts.sort
431 csharp = SourceFile.new("bam.cs", :contents => <<-INLINE_CSHARP
433 using Microsoft.WindowsMobile.DirectX;
436 expected_gestalts = [
437 Base.new(:platform, 'windows_ce_incomplete'),
438 Base.new(:platform, 'dot_net'),
441 assert_equal expected_gestalts.sort, csharp.gestalts.sort
445 make = SourceFile.new("Makefile", :contents => <<-INLINE_MAKEFILE
449 expected_gestalts = [
450 Base.new(:platform, 'gcc'),
452 assert_equal expected_gestalts.sort, make.gestalts.sort
456 c = SourceFile.new("foo.c", :contents => <<-INLINE_C
460 expected_gestalts = [
461 Base.new(:platform, 'native_code'),
463 assert_equal expected_gestalts.sort, c.gestalts.sort
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
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>
478 expected_gestalts = [ Base.new(:platform, 'flex') ]
479 assert_equal expected_gestalts.sort, as.gestalts.sort