win32-dir 0.4.7 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile DELETED
@@ -1,38 +0,0 @@
1
- require 'rake'
2
- require 'rake/clean'
3
- require 'rake/testtask'
4
-
5
- CLEAN.include('**/*.gem', '**/*.log')
6
-
7
- namespace 'gem' do
8
- desc "Create the win32-dir gem"
9
- task :create => [:clean] do
10
- Dir["*.gem"].each{ |f| File.delete(f) }
11
- spec = eval(IO.read('win32-dir.gemspec'))
12
-
13
- if Gem::VERSION.to_f < 2.0
14
- Gem::Builder.new(spec).build
15
- else
16
- require 'rubygems/package'
17
- Gem::Package.build(spec)
18
- end
19
- end
20
-
21
- desc "Install the win32-dir gem"
22
- task :install => [:create] do
23
- file = Dir["*.gem"].first
24
- sh "gem install #{file}"
25
- end
26
- end
27
-
28
- desc "Run the example program"
29
- task :example do
30
- sh "ruby -Ilib examples/dir_example.rb"
31
- end
32
-
33
- Rake::TestTask.new do |t|
34
- t.warning = true
35
- t.verbose = true
36
- end
37
-
38
- task :default => :test
@@ -1,23 +0,0 @@
1
- ####################################################################
2
- # dir_example.rb
3
- #
4
- # Generic test script for general futzing. Modify as you see fit.
5
- # You can run this via the 'rake example' task.
6
- ####################################################################
7
- require 'win32/dir'
8
-
9
- puts "Admin Tools:\t\t" + Dir::ADMINTOOLS
10
- puts "Common Admin Tools:\t" + Dir::COMMON_ADMINTOOLS
11
- puts "App Data:\t\t" + Dir::APPDATA
12
- puts "Common App Data:\t" + Dir::COMMON_APPDATA
13
- puts "Common Documents:\t" + Dir::COMMON_DOCUMENTS
14
- puts "Cookies:\t\t" + Dir::COOKIES
15
- puts "History:\t\t" + Dir::HISTORY
16
- puts "Internet Cache:\t\t" + Dir::INTERNET_CACHE
17
- puts "Local App Data:\t\t" + Dir::LOCAL_APPDATA
18
- puts "My Pictures:\t\t" + Dir::MYPICTURES
19
- puts "Personal:\t\t" + Dir::PERSONAL
20
- puts "Program Files:\t\t" + Dir::PROGRAM_FILES
21
- puts "Program Files Common:\t" + Dir::PROGRAM_FILES_COMMON
22
- puts "System:\t\t\t" + Dir::SYSTEM
23
- puts "Windows:\t\t" + Dir::WINDOWS
@@ -1,452 +0,0 @@
1
- # encoding: utf-8
2
- ###########################################################################
3
- # test_win32_dir.rb
4
- #
5
- # Test suite for the win32-dir library. You should run this test case
6
- # via the 'rake test' task.
7
- ###########################################################################
8
- require 'test-unit'
9
- require 'win32/dir'
10
- require 'tmpdir'
11
- require 'fileutils'
12
- require 'pathname'
13
-
14
- class TC_Win32_Dir < Test::Unit::TestCase
15
- def self.startup
16
- @@java = RUBY_PLATFORM == 'java'
17
- @@temp = Dir.tmpdir
18
- @@from = File.join(@@temp, "test_from_directory")
19
- Dir.mkdir(@@from)
20
- end
21
-
22
- def setup
23
- @ascii_to = File.join(@@temp, "test_to_directory")
24
- @unicode_to = File.join(@@temp, "Ελλάσ")
25
- @test_file = File.join(@@from, "test.txt")
26
- end
27
-
28
- test "version number is set to expected value" do
29
- assert_equal('0.4.7', Dir::VERSION)
30
- end
31
-
32
- test 'glob handles backslashes' do
33
- pattern = "C:\\Program Files\\Common Files\\System\\*.dll"
34
- assert_nothing_raised{ Dir.glob(pattern) }
35
- assert_true(Dir.glob(pattern).size > 0)
36
- end
37
-
38
- test 'glob handles multiple strings' do
39
- pattern1 = "C:\\Program Files\\Common Files\\System\\*.dll"
40
- pattern2 = "C:\\Windows\\*.exe"
41
- assert_nothing_raised{ Dir.glob([pattern1, pattern2]) }
42
- assert_true(Dir.glob([pattern1, pattern2]).size > 0)
43
- end
44
-
45
- test 'glob still observes flags' do
46
- assert_nothing_raised{ Dir.glob('*', File::FNM_DOTMATCH ) }
47
- assert_true(Dir.glob('*', File::FNM_DOTMATCH).include?('.'))
48
- end
49
-
50
- test 'glob still honors block' do
51
- array = []
52
- assert_nothing_raised{ Dir.glob('*', File::FNM_DOTMATCH ){ |m| array << m } }
53
- assert_true(array.include?('.'))
54
- end
55
-
56
- test 'glob handles Pathname objects' do
57
- pattern1 = Pathname.new("C:\\Program Files\\Common Files\\System\\*.dll")
58
- pattern2 = Pathname.new("C:\\Windows\\*.exe")
59
- assert_nothing_raised{ Dir.glob([pattern1, pattern2]) }
60
- assert_true(Dir.glob([pattern1, pattern2]).size > 0)
61
- end
62
-
63
- test 'ref handles backslashes' do
64
- pattern = "C:\\Program Files\\Common Files\\System\\*.dll"
65
- assert_nothing_raised{ Dir[pattern] }
66
- assert_true(Dir[pattern].size > 0)
67
- end
68
-
69
- test 'ref handles multiple arguments' do
70
- pattern1 = "C:\\Program Files\\Common Files\\System\\*.dll"
71
- pattern2 = "C:\\Windows\\*.exe"
72
- assert_nothing_raised{ Dir[pattern1, pattern2] }
73
- assert_true(Dir[pattern1, pattern2].size > 0)
74
- end
75
-
76
- test 'ref handles pathname arguments' do
77
- pattern1 = Pathname.new("C:\\Program Files\\Common Files\\System\\*.dll")
78
- pattern2 = Pathname.new("C:\\Windows\\*.exe")
79
- assert_nothing_raised{ Dir[pattern1, pattern2] }
80
- assert_true(Dir[pattern1, pattern2].size > 0)
81
- end
82
-
83
- test "create_junction basic functionality" do
84
- assert_respond_to(Dir, :create_junction)
85
- end
86
-
87
- test "create_junction works as expected with ascii characters" do
88
- assert_nothing_raised{ Dir.create_junction(@ascii_to, @@from) }
89
- assert_true(File.exists?(@ascii_to))
90
- File.open(@test_file, 'w'){ |fh| fh.puts "Hello World" }
91
- assert_equal(Dir.entries(@@from), Dir.entries(@ascii_to))
92
- end
93
-
94
- test "create_junction works as expected with unicode characters" do
95
- assert_nothing_raised{ Dir.create_junction(@unicode_to, @@from) }
96
- assert_true(File.exists?(@unicode_to))
97
- File.open(@test_file, 'w'){ |fh| fh.puts "Hello World" }
98
- assert_equal(Dir.entries(@@from), Dir.entries(@unicode_to))
99
- end
100
-
101
- test "create_junction works as expected with pathname objects" do
102
- assert_nothing_raised{ Dir.create_junction(Pathname.new(@ascii_to), Pathname.new(@@from)) }
103
- assert_true(File.exists?(@ascii_to))
104
- File.open(@test_file, 'w'){ |fh| fh.puts "Hello World" }
105
- assert_equal(Dir.entries(@@from), Dir.entries(@ascii_to))
106
- end
107
-
108
- test "read_junction works as expected with ascii characters" do
109
- assert_nothing_raised{ Dir.create_junction(@ascii_to, @@from) }
110
- assert_true(File.exists?(@ascii_to))
111
- assert_equal(Dir.read_junction(@ascii_to), @@from)
112
- end
113
-
114
- test "read_junction works as expected with unicode characters" do
115
- assert_nothing_raised{ Dir.create_junction(@unicode_to, @@from) }
116
- assert_true(File.exists?(@unicode_to))
117
- assert_equal(Dir.read_junction(@unicode_to), @@from)
118
- end
119
-
120
- test "read_junction with unicode characters is joinable" do
121
- assert_nothing_raised{ Dir.create_junction(@unicode_to, @@from) }
122
- assert_true(File.exists?(@unicode_to))
123
- assert_nothing_raised{ File.join(Dir.read_junction(@unicode_to), 'foo') }
124
- end
125
-
126
- test "read_junction works as expected with pathname objects" do
127
- assert_nothing_raised{ Dir.create_junction(Pathname.new(@ascii_to), Pathname.new(@@from)) }
128
- assert_true(File.exists?(@ascii_to))
129
- assert_equal(Dir.read_junction(@ascii_to), @@from)
130
- end
131
-
132
- test "junction? method returns boolean value" do
133
- assert_respond_to(Dir, :junction?)
134
- assert_nothing_raised{ Dir.create_junction(@ascii_to, @@from) }
135
- assert_false(Dir.junction?(@@from))
136
- assert_true(Dir.junction?(@ascii_to))
137
- assert_true(Dir.junction?(Pathname.new(@ascii_to)))
138
- end
139
-
140
- test "reparse_dir? is an aliase for junction?" do
141
- assert_respond_to(Dir, :reparse_dir?)
142
- assert_true(Dir.method(:reparse_dir?) == Dir.method(:junction?))
143
- end
144
-
145
- test "empty? method returns expected result" do
146
- assert_respond_to(Dir, :empty?)
147
- assert_false(Dir.empty?("C:\\")) # One would think
148
- assert_true(Dir.empty?(@@from))
149
- assert_true(Dir.empty?(Pathname.new(@@from)))
150
- end
151
-
152
- test "pwd basic functionality" do
153
- omit_if(@@java)
154
- assert_respond_to(Dir, :pwd)
155
- assert_nothing_raised{ Dir.pwd }
156
- assert_kind_of(String, Dir.pwd)
157
- end
158
-
159
- test "pwd returns full path even if short path was just used" do
160
- omit_if(@@java)
161
- Dir.chdir("C:\\Progra~1")
162
- assert_equal("C:\\Program Files", Dir.pwd)
163
- end
164
-
165
- test "pwd returns full path if long path was just used" do
166
- omit_if(@@java)
167
- Dir.chdir("C:\\Program Files")
168
- assert_equal("C:\\Program Files", Dir.pwd)
169
- end
170
-
171
- test "pwd uses standard case conventions" do
172
- omit_if(@@java)
173
- Dir.chdir("C:\\PROGRAM FILES")
174
- assert_equal("C:\\Program Files", Dir.pwd)
175
- end
176
-
177
- test "pwd converts forward slashes to backslashes" do
178
- omit_if(@@java)
179
- Dir.chdir("C:/Program Files")
180
- assert_equal("C:\\Program Files", Dir.pwd)
181
- end
182
-
183
- test "pwd and getwd are aliases" do
184
- omit_if(@@java)
185
- assert_true(Dir.method(:getwd) == Dir.method(:pwd))
186
- end
187
-
188
- test "admintools constant is set" do
189
- assert_not_nil(Dir::ADMINTOOLS)
190
- assert_kind_of(String, Dir::ADMINTOOLS)
191
- end
192
-
193
- test "altstartup constant is set" do
194
- assert_not_nil(Dir::ALTSTARTUP)
195
- assert_kind_of(String, Dir::ALTSTARTUP)
196
- end
197
-
198
- test "appdata constant is set" do
199
- assert_not_nil(Dir::APPDATA)
200
- assert_kind_of(String, Dir::APPDATA)
201
- end
202
-
203
- test "bitbucket constant is set" do
204
- assert_not_nil(Dir::BITBUCKET)
205
- assert_kind_of(String, Dir::BITBUCKET)
206
- end
207
-
208
- test "cdburn area is set" do
209
- assert_not_nil(Dir::CDBURN_AREA)
210
- assert_kind_of(String, Dir::CDBURN_AREA)
211
- end
212
-
213
- test "common admintools is set" do
214
- assert_not_nil(Dir::COMMON_ADMINTOOLS)
215
- assert_kind_of(String, Dir::COMMON_ADMINTOOLS)
216
- end
217
-
218
- test "common_altstartup constant is set" do
219
- assert_not_nil(Dir::COMMON_ALTSTARTUP)
220
- assert_kind_of(String, Dir::COMMON_ALTSTARTUP)
221
- end
222
-
223
- test "common_appdata constant is set" do
224
- assert_not_nil(Dir::COMMON_APPDATA)
225
- assert_kind_of(String, Dir::COMMON_APPDATA)
226
- end
227
-
228
- test "common desktopdirectory constant is set" do
229
- assert_not_nil(Dir::COMMON_DESKTOPDIRECTORY)
230
- assert_kind_of(String, Dir::COMMON_DESKTOPDIRECTORY)
231
- end
232
-
233
- test "common_documents constant is set" do
234
- assert_not_nil(Dir::COMMON_DOCUMENTS)
235
- assert_kind_of(String, Dir::COMMON_DOCUMENTS)
236
- end
237
-
238
- test "common_favorites constant is set" do
239
- assert_not_nil(Dir::COMMON_FAVORITES)
240
- assert_kind_of(String, Dir::COMMON_FAVORITES)
241
- end
242
-
243
- test "common_music constant is set" do
244
- assert_not_nil(Dir::COMMON_MUSIC)
245
- assert_kind_of(String, Dir::COMMON_MUSIC)
246
- end
247
-
248
- test "common_pictures constant is set" do
249
- assert_not_nil(Dir::COMMON_PICTURES)
250
- assert_kind_of(String, Dir::COMMON_PICTURES)
251
- end
252
-
253
- test "common_programs constant is set" do
254
- assert_not_nil(Dir::COMMON_PROGRAMS)
255
- assert_kind_of(String, Dir::COMMON_PROGRAMS)
256
- end
257
-
258
- test "common_startmenu constant is set" do
259
- assert_not_nil(Dir::COMMON_STARTMENU)
260
- assert_kind_of(String, Dir::COMMON_STARTMENU)
261
- end
262
-
263
- test "common_startup constant is set" do
264
- assert_not_nil(Dir::COMMON_STARTUP)
265
- assert_kind_of(String, Dir::COMMON_STARTUP)
266
- end
267
-
268
- test "common_templates constant is set" do
269
- assert_not_nil(Dir::COMMON_TEMPLATES)
270
- assert_kind_of(String, Dir::COMMON_TEMPLATES)
271
- end
272
-
273
- test "common_video constant is set" do
274
- assert_not_nil(Dir::COMMON_VIDEO)
275
- assert_kind_of(String, Dir::COMMON_VIDEO)
276
- end
277
-
278
- test "controls constant is set" do
279
- assert_not_nil(Dir::CONTROLS)
280
- assert_kind_of(String, Dir::CONTROLS)
281
- end
282
-
283
- test "cookies constant is set" do
284
- assert_not_nil(Dir::COOKIES)
285
- assert_kind_of(String, Dir::COOKIES)
286
- end
287
-
288
- test "desktop constant is set" do
289
- assert_not_nil(Dir::DESKTOP)
290
- assert_kind_of(String, Dir::DESKTOP)
291
- end
292
-
293
- test "desktopdirectory is set" do
294
- assert_not_nil(Dir::DESKTOPDIRECTORY)
295
- assert_kind_of(String, Dir::DESKTOPDIRECTORY)
296
- end
297
-
298
- test "drives constant is set" do
299
- assert_not_nil(Dir::DRIVES)
300
- assert_kind_of(String, Dir::DRIVES)
301
- end
302
-
303
- test "favorites constant is set" do
304
- assert_not_nil(Dir::FAVORITES)
305
- assert_kind_of(String, Dir::FAVORITES)
306
- end
307
-
308
- test "fonts constant is set" do
309
- assert_not_nil(Dir::FONTS)
310
- assert_kind_of(String, Dir::FONTS)
311
- end
312
-
313
- test "history constant is set" do
314
- assert_not_nil(Dir::HISTORY)
315
- assert_kind_of(String, Dir::HISTORY)
316
- end
317
-
318
- test "internet constant is set" do
319
- assert_not_nil(Dir::INTERNET)
320
- assert_kind_of(String, Dir::INTERNET)
321
- end
322
-
323
- test "internet_cache constant is set" do
324
- assert_not_nil(Dir::INTERNET_CACHE)
325
- assert_kind_of(String, Dir::INTERNET_CACHE)
326
- end
327
-
328
- test "local_appdata constant is set" do
329
- assert_not_nil(Dir::LOCAL_APPDATA)
330
- assert_kind_of(String, Dir::LOCAL_APPDATA)
331
- end
332
-
333
- test "mydocuments constant is set" do
334
- assert_not_nil(Dir::MYDOCUMENTS)
335
- assert_kind_of(String, Dir::MYDOCUMENTS)
336
- end
337
-
338
- test "mymusic constant is set" do
339
- assert_not_nil(Dir::MYMUSIC)
340
- assert_kind_of(String, Dir::MYMUSIC)
341
- end
342
-
343
- test "mypictures constant is set" do
344
- assert_not_nil(Dir::MYPICTURES)
345
- assert_kind_of(String, Dir::MYPICTURES)
346
- end
347
-
348
- test "myvideo constant is set" do
349
- assert_not_nil(Dir::MYVIDEO)
350
- assert_kind_of(String, Dir::MYVIDEO)
351
- end
352
-
353
- test "nethood constant is set" do
354
- assert_not_nil(Dir::NETHOOD)
355
- assert_kind_of(String, Dir::NETHOOD)
356
- end
357
-
358
- test "network constant is set" do
359
- assert_not_nil(Dir::NETWORK)
360
- assert_kind_of(String, Dir::NETWORK)
361
- end
362
-
363
- test "personal constant is set" do
364
- assert_not_nil(Dir::PERSONAL)
365
- assert_kind_of(String, Dir::PERSONAL)
366
- end
367
-
368
- test "printers cosntant is set" do
369
- assert_not_nil(Dir::PRINTERS)
370
- assert_kind_of(String, Dir::PRINTERS)
371
- end
372
-
373
- test "printhood constant is set" do
374
- assert_not_nil(Dir::PRINTHOOD)
375
- assert_kind_of(String, Dir::PRINTHOOD)
376
- end
377
-
378
- test "profile constant is set" do
379
- assert_not_nil(Dir::PROFILE)
380
- assert_kind_of(String, Dir::PROFILE)
381
- end
382
-
383
- test "program_files constant is set" do
384
- assert_not_nil(Dir::PROGRAM_FILES)
385
- assert_kind_of(String, Dir::PROGRAM_FILES)
386
- end
387
-
388
- test "program_files_common constant is set" do
389
- assert_not_nil(Dir::PROGRAM_FILES_COMMON)
390
- assert_kind_of(String, Dir::PROGRAM_FILES_COMMON)
391
- end
392
-
393
- test "programs constant is set" do
394
- assert_not_nil(Dir::PROGRAMS)
395
- assert_kind_of(String, Dir::PROGRAMS)
396
- end
397
-
398
- test "recent constant is set" do
399
- assert_not_nil(Dir::RECENT)
400
- assert_kind_of(String, Dir::RECENT)
401
- end
402
-
403
- test "sendto constant is set" do
404
- assert_not_nil(Dir::SENDTO)
405
- assert_kind_of(String, Dir::SENDTO)
406
- end
407
-
408
- test "startmenu constant is set" do
409
- assert_not_nil(Dir::STARTMENU)
410
- assert_kind_of(String, Dir::STARTMENU)
411
- end
412
-
413
- test "startup constant is set" do
414
- assert_not_nil(Dir::STARTUP)
415
- assert_kind_of(String, Dir::STARTUP)
416
- end
417
-
418
- test "system constant is set" do
419
- assert_not_nil(Dir::SYSTEM)
420
- assert_kind_of(String, Dir::SYSTEM)
421
- end
422
-
423
- test "templates constant is set" do
424
- assert_not_nil(Dir::TEMPLATES)
425
- assert_kind_of(String, Dir::TEMPLATES)
426
- end
427
-
428
- test "windows constant is set" do
429
- assert_not_nil(Dir::WINDOWS)
430
- assert_kind_of(String, Dir::WINDOWS)
431
- end
432
-
433
- test "constants are ascii_compatible?" do
434
- assert_true(Dir::COMMON_APPDATA.encoding.ascii_compatible?)
435
- assert_nothing_raised{ File.join(Dir::COMMON_APPDATA, 'foo') }
436
- end
437
-
438
- test "ffi functions are private" do
439
- assert_not_respond_to(Dir, :SHGetFolderPathW)
440
- end
441
-
442
- def teardown
443
- FileUtils.rm_rf(@ascii_to)
444
- FileUtils.rm_rf(@unicode_to)
445
- end
446
-
447
- def self.shutdown
448
- FileUtils.rm_rf(@@from)
449
- @@test_home = nil
450
- @@from = nil
451
- end
452
- end