Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

201 lines
4.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1992, Microsoft Corporation.
  4. //
  5. // File: RCSTTEST.CXX
  6. //
  7. // Contents: Recoverable Stream Tests.
  8. //
  9. // History: 09-Feb-1994 SrikantS Created.
  10. //
  11. //----------------------------------------------------------------------------
  12. #include <pch.cxx>
  13. #pragma hdrstop
  14. #include <rcsttest.hxx>
  15. IMPLEMENT_UNWIND( CRcovStorageTest );
  16. CRcovStorageTest::CRcovStorageTest( PStorage & storage )
  17. : _storage(storage),
  18. _pObj(_storage.QueryTestLog()), _sObj(_pObj)
  19. {
  20. END_CONSTRUCTION(CRcovStorageTest);
  21. }
  22. #pragma pack(4)
  23. const CB_STR = 92;
  24. struct CDataRec {
  25. char name[CB_STR];
  26. ULONG num1;
  27. ULONG num2;
  28. };
  29. const CB_REC = sizeof(CDataRec);
  30. #pragma pack()
  31. void CRcovStorageTest::AppendTest( const char * szInfo, ULONG nRec )
  32. {
  33. Win4Assert( HIWORD(nRec) == 0 );
  34. Win4Assert( szInfo );
  35. CDataRec databuf;
  36. strncpy( databuf.name, szInfo, CB_STR-1);
  37. databuf.name[CB_STR-1] = 0;
  38. BOOL fCommit = TRUE;
  39. CRcovStrmAppendTrans trans( *_pObj );
  40. CRcovStrmAppendIter iter( trans, sizeof(databuf) );
  41. ULONG nCount =
  42. _pObj->GetHeader().GetCount(_pObj->GetHeader().GetBackup());
  43. for ( ULONG i = 0 ; i < nRec ; i ++ ) {
  44. databuf.num1 = nCount++;
  45. iter.AppendRec(&databuf);
  46. }
  47. if ( fCommit ) {
  48. trans.Commit();
  49. }
  50. }
  51. void CRcovStorageTest::ReadTest( ULONG nRec )
  52. {
  53. CDataRec databuf;
  54. //
  55. // First create a recoverable storage object.
  56. //
  57. CRcovStrmReadTrans trans( *_pObj );
  58. CRcovStrmReadIter iter( trans, sizeof(databuf) );
  59. while ( !iter.AtEnd() ) {
  60. iter.GetRec( &databuf );
  61. databuf.name[CB_STR-1] = 0;
  62. #if defined(KERNEL)
  63. DbgPrint("%s %u\n", databuf.name, databuf.num1 );
  64. #else
  65. printf("%s %u\n", databuf.name, databuf.num1 );
  66. #endif // KERNEL
  67. }
  68. BYTE * pDumb = new BYTE [100];
  69. delete [] pDumb;
  70. }
  71. void CRcovStorageTest::WriteTest( const char *szInfo, ULONG nRec )
  72. {
  73. Win4Assert( HIWORD(nRec) == 0 );
  74. Win4Assert( szInfo );
  75. BOOL fCommit = TRUE;
  76. CDataRec databuf;
  77. strncpy( databuf.name, szInfo, CB_STR-1);
  78. databuf.name[CB_STR-1] = 0;
  79. CRcovStrmWriteTrans trans( *_pObj );
  80. CRcovStrmWriteIter iter( trans, sizeof(databuf) );
  81. ULONG nCount = 0;
  82. trans.Seek(0);
  83. for ( ULONG i = 0 ; (i < nRec); i ++ ) {
  84. databuf.num1 = nCount++;
  85. iter.SetRec( &databuf );
  86. }
  87. nCount = max( nCount,
  88. _pObj->GetHeader().GetCount(_pObj->GetHeader().GetBackup()) );
  89. _pObj->GetHeader().SetCount(_pObj->GetHeader().GetBackup(), nCount );
  90. if ( fCommit ) {
  91. trans.Commit();
  92. }
  93. }
  94. ULONG RoundUp( ULONG num, ULONG divisor )
  95. {
  96. Win4Assert( 0 != divisor );
  97. ULONG temp = (num+divisor-1)/divisor * divisor;
  98. return temp;
  99. }
  100. ULONG Trunc( ULONG num, ULONG divisor )
  101. {
  102. Win4Assert( 0 != divisor );
  103. ULONG temp = (num/divisor) * divisor;
  104. return temp;
  105. }
  106. void CRcovStorageTest::SetSizeTest( ULONG cbNew )
  107. {
  108. cbNew = RoundUp( cbNew, CB_REC );
  109. ULONG nCount = cbNew/CB_REC;
  110. CRcovStrmMDTrans trans(*_pObj, CRcovStrmMDTrans::mdopSetSize, cbNew );
  111. _pObj->GetHeader().SetCount( _pObj->GetHeader().GetBackup(), 0 );
  112. trans.Commit();
  113. }
  114. void CRcovStorageTest::ShrinkTest( ULONG cbDelta )
  115. {
  116. ULONG cbTotal =
  117. _pObj->GetHeader().GetUserDataSize(_pObj->GetHeader().GetBackup());
  118. if ( cbDelta == 0 ) {
  119. cbDelta = cbTotal/2;
  120. }
  121. cbDelta = RoundUp( cbDelta, CB_REC );
  122. cbDelta = min( cbDelta, cbTotal );
  123. ULONG nNewCount = (cbTotal-cbDelta)/CB_REC;
  124. CRcovStrmMDTrans trans( *_pObj,
  125. CRcovStrmMDTrans::mdopBackCompact, cbDelta);
  126. _pObj->GetHeader().SetCount( _pObj->GetHeader().GetBackup(), nNewCount );
  127. trans.Commit();
  128. }
  129. void CRcovStorageTest::GrowTest( ULONG cbDelta )
  130. {
  131. cbDelta = RoundUp( cbDelta, CB_REC );
  132. CRcovStrmMDTrans trans( *_pObj, CRcovStrmMDTrans::mdopGrow, cbDelta );
  133. trans.Commit();
  134. }
  135. void CRcovStorageTest::ShrinkFrontTest( ULONG cbDelta )
  136. {
  137. ULONG cbTotal =
  138. _pObj->GetHeader().GetUserDataSize(_pObj->GetHeader().GetBackup());
  139. if ( cbDelta == 0 ) {
  140. cbDelta = cbTotal/2;
  141. }
  142. cbDelta = RoundUp( cbDelta, CB_REC );
  143. cbDelta = min( cbDelta, cbTotal );
  144. ULONG nNewCount = (cbTotal-cbDelta)/CB_REC;
  145. CRcovStrmMDTrans trans( *_pObj,
  146. CRcovStrmMDTrans::mdopFrontShrink, cbDelta );
  147. _pObj->GetHeader().SetCount( _pObj->GetHeader().GetBackup(), nNewCount );
  148. trans.Commit();
  149. }