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