home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 Mobile / Chip_Mobile_2001.iso / palm / business / printcar / printcar.exe / tests / Util / AppPreferencesStreamTest.cc next >
C/C++ Source or Header  |  2000-06-03  |  2KB  |  67 lines

  1. //
  2. //  $Id: AppPreferencesStreamTest.cc,v 1.1.1.1 2000/06/02 22:22:57 sergey Exp $
  3. //
  4.  
  5. #include <Pilot.h>
  6. #include <stdio.h>
  7. #include "../Test.h"
  8. #include "Util/AppPreferencesInputStream.h"
  9. #include "Util/AppPreferencesOutputStream.h"
  10.  
  11.  
  12. namespace Util
  13. {
  14.     const char* TestString = "Hello!";
  15.     const DWord CreatorID  = 'PrCT';
  16.  
  17.     class AppPreferencesStreamTest: public Test
  18.     {
  19.     public:
  20.         virtual const char* name() const { return "AppPreferencesStreamTest"; }
  21.  
  22.         virtual void runTest()
  23.         {
  24.             testOutputStream();
  25.             testInputStream();
  26.         }
  27.  
  28.         void testOutputStream()
  29.         {
  30.             AppPreferencesOutputStream stream;
  31.  
  32.             stream.open(CreatorID, 0, 0);
  33.  
  34.             stream.write((long)3);
  35.             stream.write(TestString);
  36.             stream.write((int)1);
  37.             stream.write((char)2);
  38.  
  39.             stream.open(CreatorID, 0, 0);
  40.             stream.close();
  41.         }
  42.  
  43.         void testInputStream()
  44.         {
  45.             AppPreferencesInputStream stream;
  46.  
  47.             testAssert(stream.open(CreatorID, 0));
  48.  
  49.             testAssert(stream.readAs<long>() == 3);
  50.  
  51.             char buff[256];
  52.             int readSize = strlen(TestString)+1;
  53.             testAssert(stream.readAsString(buff, readSize) == readSize);
  54.             testAssert(StrCompare(TestString, buff) == 0);
  55.  
  56.             testAssert(stream.readAs<int>() == 1);
  57.             testAssert(stream.readAs<char>() == 2);
  58.         }
  59.     };
  60. }
  61.  
  62. Test& GetAppPreferencesStreamTest()
  63. {
  64.     static Util::AppPreferencesStreamTest test;
  65.     return test;
  66. }
  67.