File: tilde.m

package info (click to toggle)
gnustep-base 1.31.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,580 kB
  • sloc: objc: 239,446; ansic: 36,519; cpp: 122; sh: 112; makefile: 100; xml: 32
file content (83 lines) | stat: -rw-r--r-- 2,812 bytes parent folder | download | duplicates (2)
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
#import "Testing.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSPathUtilities.h>
#import <Foundation/NSString.h>

int main()
{
  START_SET("tilde")
  NSString      *home = NSHomeDirectory();
  NSString      *tmp;

  PASS_EQUAL([home stringByAbbreviatingWithTildeInPath], @"~",
   "home directory becomes tilde");

  tmp = [home stringByAppendingPathComponent: @"Documents"];
  PASS_EQUAL([tmp stringByAbbreviatingWithTildeInPath], @"~/Documents",
    "the Documents subdirectory becomes ~/Documents");
  
  tmp = [home stringByAppendingString: @"/Documents"];
  PASS_EQUAL([tmp stringByAbbreviatingWithTildeInPath], @"~/Documents",
    "trailing slash removed");

  tmp = [home stringByAppendingString: @"//Documents///"];
  PASS_EQUAL([tmp stringByAbbreviatingWithTildeInPath], @"~/Documents",
    "multiple slashes removed");

  tmp = [home stringByAppendingString: @"/Documents//.."];
  PASS_EQUAL([tmp stringByAbbreviatingWithTildeInPath], @"~/Documents/..",
    "upper directory reference retained");

  tmp = [home stringByAppendingString: @"/Documents/./.."];
  PASS_EQUAL([tmp stringByAbbreviatingWithTildeInPath], @"~/Documents/./..",
    "dot directory reference retained");

#if defined(_WIN32)
  SKIP("multiple slashes can't be removed on Windows")
#else
  /* This test can't work on windows, because the home directory of a
   * user doesn't start with a slash... don't run it on _WIN32
   */
  tmp = [NSString stringWithFormat: @"////%@//Documents///", home];
  PASS_EQUAL([tmp stringByAbbreviatingWithTildeInPath], @"~/Documents",
    "multiple slashes removed");
#endif

  PASS_EQUAL([@"//////Documents///" stringByAbbreviatingWithTildeInPath],
    @"/Documents",
    "multiple slashes removed without tilde replacement");

  PASS_EQUAL([@".//////Documents///" stringByAbbreviatingWithTildeInPath],
    @"./Documents",
    "multiple slashes removed without tilde replacement");

  END_SET("tilde")

  START_SET("tilde abbreviation for other home")

#if defined(_WIN32)
  SKIP("tilde abbreviation test not implemented on Windows")
#else
  NSString      *home = NSHomeDirectory();
  NSString      *tmp;
  /* The idea here is to use a home directory for a user other than the
   * current one.  We pick root as a user which will exist on most systems.
   * If the current user is root then this will not work, so we skip the
   * test in that case.
   */
  tmp  = NSHomeDirectoryForUser(@"root");
  if (0 == [tmp length])
    {
      SKIP("can't determine root's home directory for tilde test")
    }
  if (YES == [tmp isEqual: home])
    {
      SKIP("home directory of current user is root's home")
    }
  PASS_EQUAL([tmp stringByAbbreviatingWithTildeInPath], tmp,
    "tilde does nothing for root's home");
#endif

  END_SET("tilde abbreviation for other home")
  return 0;
}