Codebase list ohcount / upstream/4.0.0 test / unit / ruby / gestalt / definitions_test.rb
upstream/4.0.0

Tree @upstream/4.0.0 (Download .tar.gz)

definitions_test.rb @upstream/4.0.0raw · history · blame

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
require 'test/unit'
require File.dirname(__FILE__) + '/../../../../ruby/gestalt'

include Ohcount
include Ohcount::Gestalt

class DefinitionsTest < Ohcount::Test

	def test_zend_framework
		assert_gestalts 'zend_framework', [
      Base.new(:platform,'php'),
      Base.new(:platform,'zendframework'),
			Base.new(:platform,'scripting')
    ]
	end

	def test_php
		assert_gestalts 'php', [
      Base.new(:platform,'php'),
			Base.new(:platform,'scripting')
    ]
	end

	def test_wx_widgets
		assert_gestalts 'wx_widgets', [
      Base.new(:platform,'wxwidgets'),
      Base.new(:platform, 'native_code')
    ]
	end

	def test_eclipse_platform
		assert_gestalts 'eclipse_platform', [
      Base.new(:platform,'java'),
      Base.new(:platform,'eclipseplatform')
    ]
	end

	def test_win32_not_enough
		assert_gestalts 'win32_not_enough', [
      Base.new(:platform, 'native_code')
		]
	end

	def test_win32_enough
		assert_gestalts 'win32_enough', [
      Base.new(:platform, 'win32'),
      Base.new(:platform, 'native_code')
    ]
	end

	def test_ruby_just_enough
		assert_gestalts 'ruby_just_enough', [
      Base.new(:platform, 'ruby'),
      Base.new(:platform, 'scripting'),
      Base.new(:platform, 'native_code'),
    ]
	end

	def test_ruby_not_enough
		assert_gestalts 'ruby_not_enough', [
			Base.new(:platform, 'native_code')
		]
	end

	def test_cakephp
		assert_gestalts 'cakephp', [
      Base.new(:platform, 'php'),
      Base.new(:platform, 'cakephp'),
      Base.new(:platform, 'scripting'),
    ]
	end

	def test_symfony
		assert_platform('symfony', :php, :symfony, :scripting)
	end

	def test_pear
		assert_platform('pear', :php, :pear, :scripting)
	end

	def test_moodle
		assert_platform('moodle', :php, :moodle, :scripting)
	end

	def test_spring_framework
		assert_gestalts 'spring_framework', [
      Base.new(:platform, 'java'),
      Base.new(:platform, 'springframework')
    ]
	end

	def test_rails
		assert_platform('rails', :ruby, :rails, :scripting)
	end

	def test_jquery
		assert_platform('jquery', :javascript, :jquery, :scripting)
	end

	def test_dojo
		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>')
		expected_gestalts = [ Base.new(:platform, "dojo") ]
		assert_equal expected_gestalts.sort, h.gestalts.sort
	end

	def test_yui
		h = SourceFile.new("sample.html", :contents => '<script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/build/yahoo/yahoo-min.js" ></script>')
		expected_gestalts = [ Base.new(:platform, "yui") ]
		assert_equal expected_gestalts.sort, h.gestalts.sort
	end

	def test_python
		assert_platform('python', :python, :scripting)
	end

	def test_mac
		assert_platform('mac', :mac, :native_code)
	end

	def test_plist
		assert_platform('plist', :mac)
	end

	def test_posix
		assert_platform('posix', :posix, :native_code)
	end

	def test_x_windows
		assert_platform('xwindows', :xwindows, :native_code)
	end

	def test_kde
		assert_platform('kde', :kde, :native_code)
	end

	def test_msdos
		assert_platform('msdos', :msdos, :native_code)
	end

	def test_gtk
		assert_platform('gtk', :gtk, :native_code)
	end

	def test_drupal
		assert_platform('drupal', :php, :drupal, :scripting)
	end

	def test_vs_1
		assert_tool('vs_1', :visualstudio)
	end

	def test_eclipse
		assert_tool('eclipse', :eclipse)
	end

	def test_netbeans
		assert_tool('netbeans', :netbeans)
	end

	def test_arm
    asm = SourceFile.new("foo.S", :contents => <<-INLINE_ASM
			orrs 3, eax
      INLINE_ASM
    )

		expected_gestalts = [
			Base.new(:platform, 'arm')
		]

		assert_equal expected_gestalts.sort, asm.gestalts.sort
	end

	def test_arm_from_c_keywords
		c = SourceFile.new("foo.c", :contents => <<-INLINE_C
      #define __arm__
		INLINE_C
    )
		expected_gestalts = [
      Base.new(:platform, 'arm'),
      Base.new(:platform, 'native_code')
		]
		assert_equal expected_gestalts, c.gestalts
	end

	def test_arm_neon
    asm = SourceFile.new("foo.S", :contents => <<-INLINE_ASM
			vmov u8, s
      INLINE_ASM
    )

    expected_gestalts = [
      Base.new(:platform, 'arm'),
      Base.new(:platform, 'arm_neon')
    ]

    assert_equal expected_gestalts.sort, asm.gestalts.sort
	end

	def test_moblin_clutter
		c = SourceFile.new("foo.c", :contents => <<-INLINE_C
			  clutter_actor_queue_redraw (CLUTTER_ACTOR(label));
			INLINE_C
		)
    expected_gestalts = [
      Base.new(:platform, 'clutter'),
      Base.new(:platform, 'moblin'),
      Base.new(:platform, 'mid_combined'),
      Base.new(:platform, 'native_code')
    ]

    assert_equal expected_gestalts.sort, c.gestalts.sort
	end

	def test_moblin_by_filename
		c = SourceFile.new("moblin-netbook-system-tray.h", :contents => <<-INLINE_PERL
				#include "foo"
			INLINE_PERL
		)
    expected_gestalts = [
      Base.new(:platform, 'moblin_misc'),
      Base.new(:platform, 'moblin'),
      Base.new(:platform, 'mid_combined'),
      Base.new(:platform, 'native_code')
    ]

    assert_equal expected_gestalts.sort, c.gestalts.sort
	end

	def test_moblin_by_keyword
		c = SourceFile.new("foo.c", :contents => <<-INLINE_PERL
				proxy = dbus_g_proxy_new_for_name (conn, "org.moblin.connman",
			INLINE_PERL
		)
    expected_gestalts = [
      Base.new(:platform, 'moblin_misc'),
      Base.new(:platform, 'moblin'),
      Base.new(:platform, 'mid_combined'),
      Base.new(:platform, 'native_code')
    ]

    assert_equal expected_gestalts.sort, c.gestalts.sort
	end

	def test_nbtk
		c = SourceFile.new("foo.c", :contents => <<-INLINE_C
				button = nbtk_button_new_with_label ("Back");
			INLINE_C
		)
    expected_gestalts = [
      Base.new(:platform, 'nbtk'),
			Base.new(:platform, 'mid_combined'),
      Base.new(:platform, 'moblin'),
      Base.new(:platform, 'native_code')
    ]

    assert_equal expected_gestalts.sort, c.gestalts.sort
	end


	def test_android
    java = SourceFile.new("foo.java", :contents => <<-INLINE_C
			import android.app.Activity;
			// import dont.import.this;
      INLINE_C
    )

		names = java.gestalts.map { |g| g.name if g.type == :platform }.compact
		assert names.include?('java')
		assert names.include?('android')
		assert names.include?('mid_combined')
	end

	def test_iphone
    objective_c = SourceFile.new("foo.m", :contents => <<-OBJECTIVE_C
			 #import <Foundation/Foundation.h>
			 #import <UIKit/UIKit.h>
			 #import "WhackABugApp.h"

			 int main(int argc, char *argv[]) {
				 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
				 int ret = UIApplicationMain(argc, argv, [WhackABugApp class]);
				 [pool release];
				 return ret;
			 }
      OBJECTIVE_C
    )

    expected_gestalts = [
      Base.new(:platform, 'iphone'),
      Base.new(:platform, 'mid_combined')
    ]

    assert_equal expected_gestalts.sort, objective_c.gestalts.sort
	end

	def test_hildon
		c = SourceFile.new("foo.c", :contents => <<-INLINE_C
				HildonWindow *window;
			INLINE_C
		)
    expected_gestalts = [
      Base.new(:platform, 'hildon'),
      Base.new(:platform, 'maemo'),
      Base.new(:platform, 'native_code'),
      Base.new(:platform, 'mid_combined')
    ]

    assert_equal expected_gestalts.sort, c.gestalts.sort
	end

	def test_atom_linux
		make = SourceFile.new("makefile", :contents => <<-INLINE_MAKEFILE
			COMPILE_FLAGS=/QxL
		INLINE_MAKEFILE
    )
		expected_gestalts = [
      Base.new(:platform, 'xl_flag'),
      Base.new(:platform, 'atom')
		]
		assert_equal expected_gestalts.sort, make.gestalts.sort
	end

	def test_atom_windows
		make = SourceFile.new("makefile", :contents => <<-INLINE_MAKEFILE
			CCFLAGS = -xL
		INLINE_MAKEFILE
    )
		expected_gestalts = [
      Base.new(:platform, 'xl_flag'),
      Base.new(:platform, 'atom')
		]
		assert_equal expected_gestalts.sort, make.gestalts.sort
	end

	def test_not_atom_windows
		make = SourceFile.new("makefile", :contents => <<-INLINE_MAKEFILE
			CCFLAGS = -xLo
		INLINE_MAKEFILE
    )
		expected_gestalts = []
		assert_equal expected_gestalts.sort, make.gestalts.sort
	end

	def test_atom_sse3
		make = SourceFile.new("makefile", :contents => <<-INLINE_MAKEFILE
			COMPILE_FLAGS=-xSSE3_ATOM_FLAG
		INLINE_MAKEFILE
    )
		expected_gestalts = [
      Base.new(:platform, 'sse3_atom_flag'),
      Base.new(:platform, 'atom')
		]
		assert_equal expected_gestalts.sort, make.gestalts.sort
	end

	def test_intel_compiler

		make = SourceFile.new("Makefile", :contents => <<-INLINE_MAKEFILE
			CC = icc
		INLINE_MAKEFILE
    )
		expected_gestalts = [
      Base.new(:platform, 'intel_compiler'),
		]
		assert_equal expected_gestalts.sort, make.gestalts.sort
	end

	def test_opensso
		java = SourceFile.new("foo.java", :contents => <<-INLINE_JAVA
import com.sun.identity.authentication;
			INLINE_JAVA
		)
		platforms = java.gestalts.map { |g| g.name if g.type == :platform }.compact
		assert platforms.include?('java')
		assert platforms.include?('opensso')
	end

	def test_windows_ce
		csharp = SourceFile.new("bam.cs", :contents => <<-INLINE_CSHARP
				using System;
				using Microsoft.WindowsMobile.DirectX;
			INLINE_CSHARP
		)
    expected_gestalts = [
      Base.new(:platform, 'windows_ce_incomplete'),
      Base.new(:platform, 'dot_net'),
    ]

		assert_equal expected_gestalts.sort, csharp.gestalts.sort
	end

	def test_gcc
		make = SourceFile.new("Makefile", :contents => <<-INLINE_MAKEFILE
			CC = gcc
		INLINE_MAKEFILE
    )
		expected_gestalts = [
      Base.new(:platform, 'gcc'),
		]
		assert_equal expected_gestalts.sort, make.gestalts.sort
	end

	def test_native_code
		c = SourceFile.new("foo.c", :contents => <<-INLINE_C
			int *pcode = NULL;
		INLINE_C
    )
		expected_gestalts = [
      Base.new(:platform, 'native_code'),
		]
		assert_equal expected_gestalts.sort, c.gestalts.sort
	end

	def test_flash
		as = SourceFile.new("sample.as", :contents => 'greet.text = "Hello, world";')
		expected_gestalts = [ Base.new(:platform, "flash") ]
		assert_equal expected_gestalts.sort, as.gestalts.sort
	end

	def test_flex
		as = SourceFile.new("sample.mxml", :contents => <<-MXML
			<?xml version="1.0" encoding="utf-8"?>
			<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"></mx:Application>
		MXML
		)
		expected_gestalts = [ Base.new(:platform, 'flex') ]
		assert_equal expected_gestalts.sort, as.gestalts.sort
	end
end