Leaked source code of windows server 2003
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.

161 lines
4.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  5. //
  6. // File: laytest.cxx
  7. //
  8. // History: 15-May-96 SusiA Created
  9. //
  10. //----------------------------------------------------------------------------
  11. #include "pch.cxx"
  12. #pragma hdrstop
  13. #include "scripts.hxx"
  14. HRESULT StgLayoutDocfile(HANDLE hOld,
  15. OLECHAR const *pwcsNewName,
  16. OLECHAR const *pwcsScriptName);
  17. typedef ULONG SECT;
  18. #define FailMsg(MSG) {printf MSG; exit(1);}
  19. #define DoCmd(MSG, CODE, FAILMSG) \
  20. printf(MSG " => %s (0x%lX)\n", (sc = ResultFromScode(CODE), ScText(sc)), sc); \
  21. if (FAILED(sc)) {printf(FAILMSG "\n");}
  22. #define SHIFT(c,v) ( (c)--, (v)++)
  23. #include <assert.h>
  24. void BeginTest(void)
  25. {
  26. HRESULT hr;
  27. hr = CoInitialize(NULL);
  28. Result(hr, "CoInitialize");
  29. }
  30. void EndTest(int rc)
  31. {
  32. if (rc == 0)
  33. printf("Test SUCCEEDED\n");
  34. else
  35. printf("Test FAILED\n");
  36. CoUninitialize();
  37. exit(rc);
  38. }
  39. void PrintStat(STATSTG *pstat, BOOL fEnum)
  40. {
  41. printf("%s: '%ws'\n", pstat->type == STGTY_STORAGE ? "Storage" : "Stream",
  42. pstat->pwcsName);
  43. //printf("Type: %lu, %lu\n", pstat->type, pstat->dwStgFmt);
  44. printf("Type: %lu, %lu\n", pstat->type);
  45. if (!fEnum)
  46. printf("Mode: %lX\n", pstat->grfMode);
  47. if (pstat->type == STGTY_STREAM)
  48. {
  49. printf("Size: %lu:%lu\n", pstat->cbSize.HighPart,
  50. pstat->cbSize.LowPart);
  51. if (!fEnum)
  52. printf("Locks: %lX\n", pstat->grfLocksSupported);
  53. }
  54. else
  55. {
  56. if (pstat->ctime.dwHighDateTime != 0 ||
  57. pstat->ctime.dwLowDateTime != 0)
  58. printf("Ctime: %s\n", FileTimeText(&pstat->ctime));
  59. if (pstat->mtime.dwHighDateTime != 0 ||
  60. pstat->mtime.dwLowDateTime != 0)
  61. printf("Mtime: %s\n", FileTimeText(&pstat->mtime));
  62. if (pstat->atime.dwHighDateTime != 0 ||
  63. pstat->atime.dwLowDateTime != 0)
  64. printf("Atime: %s\n", FileTimeText(&pstat->atime));
  65. }
  66. if (!fEnum)
  67. printf("Clsid: %s\n", GuidText(&pstat->clsid));
  68. }
  69. void PrintStatInfo(STATSTG *pstat)
  70. {
  71. PrintStat(pstat, TRUE);
  72. }
  73. #define OLDFILENAME L"StartDocfile.Doc"
  74. #define NEWFILENAME L"d:\\scratch\\NewD.doc"
  75. #define SCRIPTFILENAME L"Script"
  76. #define DOCFILENAME L"d:\\nt\\private\\ole32\\stg\\async\\layout\\test\\test.doc"
  77. void t_script(void)
  78. {
  79. SCODE sc;
  80. IStorage *pstgRoot, *pstgNew, *pstgOld;
  81. ILayoutStorage *pLayout;
  82. int i;
  83. BYTE buffer[4096];
  84. sc = StgOpenLayoutDocfile(DOCFILENAME,
  85. STGM_DIRECT | STGM_READ | STGM_SHARE_EXCLUSIVE,
  86. 0,
  87. &pstgRoot);
  88. Result(sc, "StgOpenLayoutDocfile");
  89. pstgRoot->QueryInterface(IID_ILayoutStorage,(void **) &pLayout);
  90. for (i=0; i < NUMTESTS; i++)
  91. {
  92. sc = pLayout->LayoutScript(
  93. arrWord[i].LayoutArray,
  94. arrWord[i].nEntries,
  95. STG_LAYOUT_SEQUENTIAL); // sequential (all up front) control structures
  96. Result(sc, "LayoutScript");
  97. }
  98. // Write new compound file with desired layout
  99. sc = pLayout->ReLayoutDocfile(NEWFILENAME);
  100. Result(sc, "ReLayoutDocfile");
  101. sc = StgOpenStorage(NEWFILENAME,
  102. NULL,
  103. STGM_DIRECT | STGM_READ | STGM_SHARE_EXCLUSIVE,
  104. NULL,
  105. 0,
  106. &pstgNew);
  107. Result(sc, "Open new file");
  108. if (!CompareStorages(pstgRoot, pstgNew))
  109. {
  110. Fail("Files did not compare identical\n");
  111. }
  112. pLayout->Release();
  113. pstgNew->Release();
  114. pstgRoot->Release();
  115. }
  116. void __cdecl main(int argc, char **argv)
  117. {
  118. SCODE sc;
  119. BeginTest();
  120. //t_layout();
  121. t_script();
  122. EndTest(0);
  123. exit(0);
  124. }