AppendFileTest.m
上传用户:shenzhenrh
上传日期:2013-05-12
资源大小:2904k
文件大小:2k
源码类别:

信息检索与抽取

开发平台:

Unix_Linux

  1. // Swarm library. Copyright (C) 1999, 2000 Swarm Development Group.
  2. // This library is distributed without any warranty; without even the
  3. // implied warranty of merchantability or fitness for a particular purpose.
  4. // See file LICENSE for details and terms of copying.
  5. #import <objectbase.h>
  6. #import <simtools.h>
  7. #import <simtools/AppendFile.h>
  8. #import <simtools/OutFile.h>
  9. #include <misc.h>
  10. int
  11. main(int argc, const char ** argv) 
  12. {
  13.   id outFile;
  14.   id appFile;
  15.   id inFile;
  16.   char aLine[128];
  17.   initSwarmBatch(argc, argv);
  18.   // first, create a file to be "appended" to
  19.   outFile = [OutFile create: globalZone setName: "File.test"];
  20.   [outFile putString: "first thing - should not be overwritten!!n"];
  21.   [outFile drop]; // close the file
  22.   // open the same file in "append" mode
  23.   appFile = [AppendFile create: globalZone setName: "File.test"];
  24.   [appFile putString: "second thing - should be after first thing!!n"];
  25.   [appFile drop]; // close the file
  26.   // retrieve the file, using InFile object and test to see the lines
  27.   // were written to the file correctly
  28.   inFile = [InFile create: globalZone setName: "File.test"];
  29.   [inFile getLine: aLine];
  30.   printf("InFile:  %sn", aLine);
  31.   if (strcmp(aLine, "first thing - should not be overwritten!!") != 0)
  32.     {
  33.       fprintf(stderr, "first line in File.test is wrong");
  34.       return 1;
  35.     }
  36.   
  37.   [inFile skipLine];
  38.   [inFile getLine: aLine];  
  39.   printf("InFile:  %sn", aLine);
  40.   if (strcmp(aLine, "second thing - should be after first thing!!") != 0)
  41.     {
  42.       fprintf(stderr, "first line in File.test is wrong");
  43.       return 1;
  44.     }
  45.   
  46.   [inFile drop];
  47.   return 0;
  48. }