home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.bin / SourceCode / MiscKit1.2.6 / Examples / MiscString / StringTest.new.m < prev    next >
Encoding:
Text File  |  1994-02-06  |  12.4 KB  |  289 lines

  1. //
  2. // StringTest.m -- test out the String class
  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. // *******************************************************************
  15. //    This program is incomplete.  That's why it isn't compiled or run
  16. //    yet.  When finished, it will replace "StringTest.m" completely.
  17. // *******************************************************************
  18.  
  19. // To find the test for a method, search for a method name in the format
  20. // "-numOfChar:caseSensitive:" and you'll go right to it.
  21. // There is a separate, source file for testing each category, each of
  22. // which is brought into this source via an include.
  23.  
  24. // Functions left to write:
  25. //    testMiscStringComparing()
  26. //    testMiscStringFields()
  27. //    testMiscStringInsertion()
  28. //    testMiscStringModification()
  29. //    testMiscStringPatterns()
  30. //    testMiscStringReplacing()
  31. //    testMiscStringSearching()
  32. //    testMiscStringUNIX()            (incomplete)
  33.  
  34. #import <appkit/appkit.h>
  35. #import <misckit/misckit.h>
  36. #import <stdio.h>
  37.  
  38. #define MSTRINGS 12
  39. void testMiscString()
  40. {
  41.     id string[MSTRINGS]; int i;
  42.     char *charString[10];
  43.     printf("***** Testing MiscString class\n");
  44.     
  45. // Test MiscString.m methods:
  46.  
  47.     // Various ways to create new strings:
  48.     // -new, -newWithString:, -alloc and -init, -initString:, -initFromFormat:
  49.     string[0] = [MiscString new];
  50.     string[1] = [string[0] new];
  51.     string[2] = [MiscString newWithString:NULL];
  52.     string[3] = [MiscString newWithString:""];
  53.     string[4] = [MiscString newWithString:"This is String #4."];
  54.     string[5] = [[MiscString alloc] init];
  55.     string[6] = [[MiscString alloc] initString:NULL];
  56.     string[7] = [[MiscString alloc] initString:""];
  57.     string[8] = [[MiscString alloc] initString:"This is String #8."];
  58.     string[9] = [[MiscString alloc]
  59.             initFromFormat:"A formatted string:  %d %f %s.", 10, 200.3, "Yup"];
  60.  
  61.     // -allocateBuffer and -allocateBuffer:fromZone: will be exercised
  62.     // throughout this test suite, so we won't worry about them specifically.
  63.     // The same goes for -stringValue and -stringValueAndFree.  They both
  64.     // get used a lot, so we'll assume that they work OK.
  65.  
  66.     // -copyFromZone:, -freeString
  67.     string[10] = [string[8] copy]; // actually hits -copyFromZone:
  68.     string[11] = [string[9] copy]; [string[11] freeString];
  69.     // -free will be used throughout, so we won't test that here explicitly
  70.  
  71.     // -getCopyInto:
  72.     charString[0] = (char *)malloc(32);
  73.     [string[4] getCopyInto:charString[0]];
  74.     charString[1] = [string[8] getCopyInto:NULL];
  75.     for (i=0; i<12; i++)
  76.         printf("String #%d:  \"%s\", length = %d\n", i,
  77.                 [string[i] stringValue], [string[i] length]);
  78.     for (i=0; i<2; i++)
  79.         printf("CharString #%d:  \"%s\".\n", i, charString[i]);
  80.  
  81.     // -emptyString
  82.     printf("emptyString:  #2: %d,  #3: %d,  #4: %d,  #11: %d\n",
  83.             [string[2]  emptyString], [string[3]  emptyString],
  84.             [string[4]  emptyString], [string[11]  emptyString]);
  85.  
  86.     // -charAt:
  87.     printf("String #4, character at -10: '%c' (0x%x)\n",
  88.             [string[4]  charAt:-10], (unsigned)[string[4]  charAt:-10]);
  89.     printf("String #4, character at -1: '%c' (0x%x)\n",
  90.             [string[4]  charAt:-1], (unsigned)[string[4]  charAt:-1]);
  91.     printf("String #4, character at 0: '%c' (0x%x)\n",
  92.             [string[4]  charAt:0], (unsigned)[string[4]  charAt:0]);
  93.     printf("String #4, character at 1: '%c' (0x%x)\n",
  94.             [string[4]  charAt:1], (unsigned)[string[4]  charAt:1]);
  95.     printf("String #4, character at 5: '%c' (0x%x)\n",
  96.             [string[4]  charAt:5], (unsigned)[string[4]  charAt:5]);
  97.     printf("String #4, character at 50: '%c' (0x%x)\n",
  98.             [string[4]  charAt:50], (unsigned)[string[4]  charAt:50]);
  99.     printf("String #5, character at -1: '%c' (0x%x)\n",
  100.             [string[5]  charAt:-1], (unsigned)[string[5]  charAt:-1]);
  101.     printf("String #5, character at 0: '%c' (0x%x)\n",
  102.             [string[5]  charAt:0], (unsigned)[string[5]  charAt:0]);
  103.     printf("String #5, character at 1: '%c' (0x%x)\n",
  104.             [string[5]  charAt:1], (unsigned)[string[5]  charAt:1]);
  105.     printf("String #7, character at -1: '%c' (0x%x)\n",
  106.             [string[7]  charAt:-1], (unsigned)[string[7]  charAt:-1]);
  107.     printf("String #7, character at 0: '%c' (0x%x)\n",
  108.             [string[7]  charAt:0], (unsigned)[string[7]  charAt:0]);
  109.     printf("String #7, character at 1: '%c' (0x%x)\n",
  110.             [string[7]  charAt:1], (unsigned)[string[7]  charAt:1]);
  111.  
  112.     // -numOfChar:, -numOfChar:caseSensitive:
  113.     printf("String #4, num of character 's': %d\n",
  114.             [string[4]  numOfChar:'s']);
  115.     printf("String #4, num of character 's' case sense on: %d\n",
  116.             [string[4]  numOfChar:'s' caseSensitive:YES]);
  117.     printf("String #4, num of character 's' case sense off: %d\n",
  118.             [string[4]  numOfChar:'s' caseSensitive:NO]);
  119.     printf("String #4, num of character 'q': %d\n",
  120.             [string[4]  numOfChar:'q']);
  121.     printf("String #4, num of character 'q' case sense on: %d\n",
  122.             [string[4]  numOfChar:'q' caseSensitive:YES]);
  123.     printf("String #4, num of character 'q' case sense off: %d\n",
  124.             [string[4]  numOfChar:'q' caseSensitive:NO]);
  125.     printf("String #4, num of character '<0>': %d\n",
  126.             [string[4]  numOfChar:0]);
  127.     printf("String #4, num of character '<0>'  case sense on: %d\n",
  128.             [string[4]  numOfChar:0 caseSensitive:YES]);
  129.     printf("String #4, num of character '<0>'  case sense off: %d\n",
  130.             [string[4]  numOfChar:0 caseSensitive:NO]);
  131.     printf("String #5, num of character 'q': %d\n",
  132.             [string[5]  numOfChar:'q']);
  133.     printf("String #5, num of character 'q' case sense on: %d\n",
  134.             [string[5]  numOfChar:'q' caseSensitive:YES]);
  135.     printf("String #5, num of character 'q' case sense off: %d\n",
  136.             [string[5]  numOfChar:'q' caseSensitive:NO]);
  137.     printf("String #5, num of character '<0>': %d\n",
  138.             [string[5]  numOfChar:0]);
  139.     printf("String #5, num of character '<0>'  case sense on: %d\n",
  140.             [string[5]  numOfChar:0 caseSensitive:YES]);
  141.     printf("String #5, num of character '<0>'  case sense off: %d\n",
  142.             [string[5]  numOfChar:0 caseSensitive:NO]);
  143.     printf("String #7, num of character 'q': %d\n",
  144.             [string[7]  numOfChar:'q']);
  145.     printf("String #7, num of character 'q' case sense on: %d\n",
  146.             [string[7]  numOfChar:'q' caseSensitive:YES]);
  147.     printf("String #7, num of character 'q' case sense off: %d\n",
  148.             [string[7]  numOfChar:'q' caseSensitive:NO]);
  149.     printf("String #7, num of character '<0>': %d\n",
  150.             [string[7]  numOfChar:0]);
  151.     printf("String #7, num of character '<0>'  case sense on: %d\n",
  152.             [string[7]  numOfChar:0 caseSensitive:YES]);
  153.     printf("String #7, num of character '<0>'  case sense off: %d\n",
  154.             [string[7]  numOfChar:0 caseSensitive:NO]);
  155.  
  156.     // -numOfChars:, -numOfChars:caseSensitive:
  157.     printf("String #8, num of characters \"rSt\": %d\n",
  158.             [string[8]  numOfChars:"rSt"]);
  159.     printf("String #8, num of characters \"rSt\"  case sense off: %d\n",
  160.             [string[8]  numOfChars:"rSt" caseSensitive:NO]);
  161.     printf("String #8, num of characters \"rSt\"  case sense on: %d\n",
  162.             [string[8]  numOfChars:"rSt" caseSensitive:YES]);
  163.     printf("String #8, num of characters \"I\": %d\n",
  164.             [string[8]  numOfChars:"I"]);
  165.     printf("String #8, num of characters \"I\"  case sense off: %d\n",
  166.             [string[8]  numOfChars:"I" caseSensitive:NO]);
  167.     printf("String #8, num of characters \"I\"  case sense on: %d\n",
  168.             [string[8]  numOfChars:"I" caseSensitive:YES]);
  169.     printf("String #8, num of characters \"x\": %d\n",
  170.             [string[8]  numOfChars:"x"]);
  171.     printf("String #8, num of characters \"x\"  case sense off: %d\n",
  172.             [string[8]  numOfChars:"x" caseSensitive:NO]);
  173.     printf("String #8, num of characters \"x\"  case sense on: %d\n",
  174.             [string[8]  numOfChars:"x" caseSensitive:YES]);
  175.     printf("String #8, num of characters \"\": %d\n",
  176.             [string[8]  numOfChars:""]);
  177.     printf("String #8, num of characters \"\"  case sense off: %d\n",
  178.             [string[8]  numOfChars:"" caseSensitive:NO]);
  179.     printf("String #8, num of characters \"\"  case sense on: %d\n",
  180.             [string[8]  numOfChars:"" caseSensitive:YES]);
  181.     printf("String #8, num of characters \"(NULL)\": %d\n",
  182.             [string[8]  numOfChars:NULL]);
  183.     printf("String #8, num of characters \"(NULL)\"  case sense off: %d\n",
  184.             [string[8]  numOfChars:NULL caseSensitive:NO]);
  185.     printf("String #8, num of characters \"(NULL)\"  case sense on: %d\n",
  186.             [string[8]  numOfChars:NULL caseSensitive:YES]);
  187.     printf("String #5, num of characters \"xy\": %d\n",
  188.             [string[5]  numOfChars:"xy"]);
  189.     printf("String #5, num of characters \"xy\"  case sense off: %d\n",
  190.             [string[5]  numOfChars:"xy" caseSensitive:NO]);
  191.     printf("String #5, num of characters \"xy\"  case sense on: %d\n",
  192.             [string[5]  numOfChars:"xy" caseSensitive:YES]);
  193.     printf("String #5, num of characters \"x\": %d\n",
  194.             [string[5]  numOfChars:"x"]);
  195.     printf("String #5, num of characters \"x\"  case sense off: %d\n",
  196.             [string[5]  numOfChars:"x" caseSensitive:NO]);
  197.     printf("String #5, num of characters \"x\"  case sense on: %d\n",
  198.             [string[5]  numOfChars:"x" caseSensitive:YES]);
  199.     printf("String #5, num of characters \"\": %d\n",
  200.             [string[5]  numOfChars:""]);
  201.     printf("String #5, num of characters \"\"  case sense off: %d\n",
  202.             [string[5]  numOfChars:"" caseSensitive:NO]);
  203.     printf("String #5, num of characters \"\"  case sense on: %d\n",
  204.             [string[5]  numOfChars:"" caseSensitive:YES]);
  205.     printf("String #5, num of characters \"(NULL)\": %d\n",
  206.             [string[5]  numOfChars:NULL]);
  207.     printf("String #5, num of characters \"(NULL)\"  case sense off: %d\n",
  208.             [string[5]  numOfChars:NULL caseSensitive:NO]);
  209.     printf("String #5, num of characters \"(NULL)\"  case sense on: %d\n",
  210.             [string[5]  numOfChars:NULL caseSensitive:YES]);
  211.     printf("String #7, num of characters \"xy\": %d\n",
  212.             [string[7]  numOfChars:"xy"]);
  213.     printf("String #7, num of characters \"xy\"  case sense off: %d\n",
  214.             [string[7]  numOfChars:"xy" caseSensitive:NO]);
  215.     printf("String #7, num of characters \"xy\"  case sense on: %d\n",
  216.             [string[7]  numOfChars:"xy" caseSensitive:YES]);
  217.     printf("String #7, num of characters \"x\": %d\n",
  218.             [string[7]  numOfChars:"x"]);
  219.     printf("String #7, num of characters \"x\"  case sense off: %d\n",
  220.             [string[7]  numOfChars:"x" caseSensitive:NO]);
  221.     printf("String #7, num of characters \"x\"  case sense on: %d\n",
  222.             [string[7]  numOfChars:"x" caseSensitive:YES]);
  223.     printf("String #7, num of characters \"\": %d\n",
  224.             [string[7]  numOfChars:""]);
  225.     printf("String #7, num of characters \"\"  case sense off: %d\n",
  226.             [string[7]  numOfChars:"" caseSensitive:NO]);
  227.     printf("String #7, num of characters \"\"  case sense on: %d\n",
  228.             [string[7]  numOfChars:"" caseSensitive:YES]);
  229.     printf("String #7, num of characters \"(NULL)\": %d\n",
  230.             [string[7]  numOfChars:NULL]);
  231.     printf("String #7, num of characters \"(NULL)\"  case sense off: %d\n",
  232.             [string[7]  numOfChars:NULL caseSensitive:NO]);
  233.      printf("String #7, num of characters \"(NULL)\"  case sense on: %d\n",
  234.             [string[7]  numOfChars:NULL caseSensitive:YES]);
  235.  
  236.     // no test available for -stringOrderTable or -setStringOrderTable:
  237.  
  238.     // -intValue, -floatValue, -doubleValue
  239.     [string[5] setStringValue:"100x300"];
  240.     [string[6] setStringValue:"100.5x300.102"];
  241.     [string[7] setStringValue:"100.x300.102"];
  242.     [string[8] setStringValue:".1x300.102"];
  243.     [string[9] setStringValue:"0.1x300.102"];
  244.     [string[10] setStringValue:".x300.102"];
  245.     for (i=2; i<11; i++) {
  246.         printf("stringValue: \"%s\"\n", [string[i] stringValue]);
  247.         printf("doubleValue: \"%f\"\n", [string[i] doubleValue]);
  248.         printf(" floatValue: \"%f\"\n", [string[i] floatValue]);
  249.         printf("   intValue: \"%i\"\n", [string[i] intValue]);
  250.     }
  251.     
  252.     // -free
  253.     for (i=0; i<MSTRINGS; i++) [string[i] free];
  254. }
  255.  
  256. // Grab the category testing subroutines.
  257. #include "StringTestComparing.m"
  258. #include "StringTestCompat.m"
  259. #include "StringTestDebugging.m"
  260. #include "StringTestFields.m"
  261. #include "StringTestInsertion.m"
  262. #include "StringTestModification.m"
  263. #include "StringTestNEXTSTEP.m"
  264. #include "StringTestPatterns.m"
  265. #include "StringTestReplacing.m"
  266. #include "StringTestSearching.m"
  267. #include "StringTestSybase.m"
  268. #include "StringTestUNIX.m"
  269.  
  270. void main()
  271. {    // we step through each source file's methods here, by file.
  272.     // so there is one function per source file, to help keep us organized.
  273.     testMiscString();
  274.     testMiscStringComparing();
  275.     testMiscStringCompat();
  276.     testMiscStringDebugging();
  277.     testMiscStringFields();
  278.     testMiscStringInsertion();
  279.     testMiscStringModification();
  280.     testMiscStringNEXTSTEP();
  281.     testMiscStringPatterns();
  282.     testMiscStringReplacing();
  283.     testMiscStringSearching();
  284.     testMiscStringSybase();
  285.     testMiscStringUNIX();
  286.     exit(0);
  287. }
  288.  
  289.