home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.bin / SourceCode / MiscKit1.2.6 / Examples / MiscString / StringTestUNIX.m < prev   
Encoding:
Text File  |  1994-02-06  |  4.0 KB  |  105 lines

  1. //
  2. // StringTestUNIX.m -- test out the String class' UNIX category
  3. //        Written by Don Yacktman (c) 1994 by Don Yacktman.
  4. //                Version 1.0.  All rights reserved.
  5. //
  6. //        This notice may not be removed from this source code.
  7. //
  8. //    This program is included in the MiscKit by permission from the author
  9. //    and its use is governed by the MiscKit license, found in the file
  10. //    "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
  11. //    for a list of all applicable permissions and restrictions.
  12. //    
  13.  
  14. void printPathAndFileName(id aString)
  15. {
  16.     printf("Given:        \"%s\"\n", [aString stringValue]);
  17.     printf("     Path is:  \"%s\"\n", [[aString pathName] stringValueAndFree]);
  18.     printf(" Filename is:  \"%s\"\n",
  19.             [[aString fileName] stringValueAndFree]);
  20.     printf("Extension is:  \"%s\"\n",
  21.             [[aString fileExtension] stringValueAndFree]);
  22.     printf("Base name is:  \"%s\"\n",
  23.             [[aString fileBasename] stringValueAndFree]);
  24. }
  25.  
  26. #define USTRINGS 5
  27. void testMiscStringUNIX()
  28. {
  29.     id string[USTRINGS]; int i;
  30.     printf("***** Testing MiscStringUNIX category\n");
  31.  
  32. // Test MiscStringUNIX.m methods:
  33.  
  34.     // -fileName, -fileNameFromZone:, -pathName, -pathNameFromZone:
  35.     string[0] = [MiscString newWithString:
  36.     "/Net/darth/Users/don/Projects/daymisckit_proj/daymisckit-1/DAYString.m"];
  37.     printPathAndFileName(string[0]);
  38.     [string[0] setStringValue:"DAYString.m"];
  39.     printPathAndFileName(string[0]);
  40.     [string[0] setStringValue:"README"];
  41.     printPathAndFileName(string[0]);
  42.     [string[0] setStringValue:"/a/README.tar.gz"];
  43.     printPathAndFileName(string[0]);
  44.     [string[0] setStringValue:"~/.cshrc"];
  45.     printPathAndFileName(string[0]);
  46.     [string[0] setStringValue:"~/.newsrc.old"];
  47.     printPathAndFileName(string[0]);
  48.     [string[0] setStringValue:""];
  49.     printPathAndFileName(string[0]);
  50.  
  51.     // -encrypt:
  52.     [string[0] setStringValue:"Blahbla0"];
  53.     string[1] = [MiscString newWithString:"DY"];
  54.     string[2] = [MiscString newWithString:NULL];
  55.     string[3] = [MiscString newWithString:""];
  56.     string[4] = [MiscString newWithString:"Blahbla0xyzpdq"];
  57.     printf("String \"%s\" with salt \"%s\" encrypts to  \"%s\" .\n",
  58.         [string[0] stringValue], [string[1] stringValue],
  59.         [[string[0] encrypt:string[1]] stringValueAndFree]);
  60.     printf("String \"%s\" with salt \"%s\" encrypts to  \"%s\" .\n",
  61.         [string[4] stringValue], [string[1] stringValue],
  62.         [[string[4] encrypt:string[1]] stringValueAndFree]);
  63.     printf("String \"%s\" with salt \"%s\" encrypts to  \"%s\" .\n",
  64.         [string[2] stringValue], [string[1] stringValue],
  65.         [[string[2] encrypt:string[1]] stringValueAndFree]);
  66.     printf("String \"%s\" with salt \"%s\" encrypts to  \"%s\" .\n",
  67.         [string[0] stringValue], [string[2] stringValue],
  68.         [[string[0] encrypt:string[2]] stringValueAndFree]);
  69.     [string[2] setStringValue:""];
  70.     printf("String \"%s\" with salt \"%s\" encrypts to  \"%s\" .\n",
  71.         [string[3] stringValue], [string[1] stringValue],
  72.         [[string[3] encrypt:string[1]] stringValueAndFree]);
  73.     printf("String \"%s\" with salt \"%s\" encrypts to  \"%s\" .\n",
  74.         [string[0] stringValue], [string[3] stringValue],
  75.         [[string[0] encrypt:string[3]] stringValueAndFree]);
  76.  
  77.     // -replaceHomeWithTilde, -replaceTildeWithHome
  78.     [string[0] setStringValue:NXHomeDirectory()];
  79.     [string[0] cat:"/aFile.txt"];
  80.     [string[1] setStringValue:"/usr/local/bin/spew"];
  81.     for (i=0; i<4; i++)
  82.         printf("Replace home with tilde: \"%s\" to \"%s\".\n",
  83.                 [string[i] stringValue],
  84.                 [[[string[i] copy] replaceHomeWithTilde] stringValueAndFree]);
  85.     [string[0] setStringValue:"~/SomeCode.c"];
  86.     for (i=0; i<4; i++)
  87.         printf("Replace tilde with home: \"%s\" to \"%s\".\n",
  88.                 [string[i] stringValue],
  89.                 [[[string[i] copy] replaceTildeWithHome] stringValueAndFree]);
  90.  
  91.     // ***** Not yet tested!
  92.     // - addExtensionIfNeeded:(const char *)aString;
  93.     // - (BOOL)isRelativePath;
  94.     // - (BOOL)isAbsolutePath;
  95.     // - (BOOL)doesExistInFileSystem;
  96.     // - (BOOL)isFileOfType:(MiscFileType)fileType;
  97.     // - pathComponentAt:(int)index
  98.     // - (int)numberOfPathComponents
  99.     // - setDirectory:(const char *)dir file:(const char *)file;
  100.     // - initDirectory:(const char *)dir file:(const char *)file;
  101.  
  102.     for (i=0; i<USTRINGS; i++) [string[i] free];
  103. }
  104.  
  105.