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.

145 lines
4.6 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1992.
  5. //
  6. // File: illeg.cxx
  7. //
  8. // Contents: Illegitimate tests
  9. //
  10. // History: 17-Nov-92 DrewB Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "headers.cxx"
  14. #pragma hdrstop
  15. #include <io.h>
  16. #include <fcntl.h>
  17. #include <sys\types.h>
  18. #include <sys\stat.h>
  19. #include "illeg.hxx"
  20. void i_storage(void)
  21. {
  22. WStorage *pwstg;
  23. IStorage *pstg, *pstg2;
  24. IStream *pstm;
  25. IllResult("StgCreateDocfile with NULL ppstg",
  26. StgCreateDocfile(NULL, 0, 0, NULL));
  27. IllResult("StgCreateDocfile with non-zero reserved",
  28. StgCreateDocfile(NULL, 0, 1, &pstg));
  29. IllResult("StgCreateDocfile with illegal permissions",
  30. StgCreateDocfile(NULL, 0, 0, &pstg));
  31. int fd;
  32. fd = _creat(OlecsOut(DRTDF), _S_IREAD);
  33. if (fd<0)
  34. error(EXIT_BADSC, "Unable to create file '%s'\n", OlecsOut(DRTDF));
  35. _close(fd);
  36. IllResult("StgCreateDocfile with STGM_WRITE over read-only file",
  37. StgCreateDocfile(DRTDF, ROOTP(STGM_READWRITE), 0, &pstg));
  38. _chmod(OlecsOut(DRTDF), _S_IREAD | _S_IWRITE);
  39. IllResult("StgOpenStorage with NULL ppstg",
  40. StgOpenStorage(NULL, NULL, 0, NULL, 0, NULL));
  41. IllResult("StgOpenStorage with NULL name",
  42. StgOpenStorage(NULL, NULL, 0, NULL, 0, &pstg));
  43. IllResult("StgOpenStorage with illegal permissions",
  44. StgOpenStorage(DRTDF, NULL, 0xffffffff, NULL, 0, &pstg));
  45. IllResult("StgOpenStorage with non-zero reserved",
  46. StgOpenStorage(DRTDF, NULL, ROOTP(STGM_READWRITE), NULL,
  47. 1, &pstg));
  48. #if WIN32 != 300
  49. // This will work on Cairo because it will open a file storage
  50. IllResult("StgOpenStorage on non-docfile",
  51. StgOpenStorage(DRTDF, NULL, ROOTP(STGM_READWRITE), NULL,
  52. 0, &pstg));
  53. #endif
  54. WStgCreateDocfile(DRTDF, ROOTP(STGM_READWRITE) | STGM_CREATE, 0, &pwstg);
  55. pstg = pwstg->GetI();
  56. IllResult("OpenStream that doesn't exist",
  57. pstg->OpenStream(STR("NoName"), 0, STMP(STGM_READWRITE),
  58. 0, &pstm));
  59. IllResult("OpenStorage that doesn't exist",
  60. pstg->OpenStorage(STR("NoName"), NULL, STGP(STGM_READWRITE),
  61. NULL, 0, &pstg2));
  62. pwstg->Unwrap();
  63. }
  64. #define STREAMSIZE 128
  65. void i_stream(void)
  66. {
  67. WStorage *pwstg;
  68. WStream *pwstm;
  69. IStream *pstm;
  70. BYTE bBuffer[STREAMSIZE];
  71. ULONG cbRead;
  72. LARGE_INTEGER liSeek;
  73. ULARGE_INTEGER uliPos;
  74. ULARGE_INTEGER uliSize;
  75. ULARGE_INTEGER cb;
  76. WStgCreateDocfile(DRTDF, ROOTP(STGM_READWRITE), 0, &pwstg);
  77. pwstg->CreateStream(STR("Stream"), STMP(STGM_READ), 0, 0, &pwstm);
  78. pstm = pwstm->GetI();
  79. IllResult("Read with NULL buffer",
  80. pstm->Read(NULL, STREAMSIZE, NULL));
  81. fExitOnFail = FALSE;
  82. pwstm->Read(bBuffer, STREAMSIZE, &cbRead);
  83. fExitOnFail = TRUE;
  84. if (cbRead != 0)
  85. error(EXIT_BADSC, "Read %lu bytes on zero-length stream\n", cbRead);
  86. IllResult("Write with NULL buffer",
  87. pstm->Write(NULL, STREAMSIZE, NULL));
  88. IllResult("Write on read-only stream",
  89. pstm->Write(bBuffer, STREAMSIZE, NULL));
  90. LISet32(liSeek, 0);
  91. IllResult("Seek with invalid origin",
  92. pstm->Seek(liSeek, (DWORD)(~STREAM_SEEK_SET), NULL));
  93. LISet32(liSeek, (ULONG)-1);
  94. IllResult("Seek before beginning",
  95. pstm->Seek(liSeek, STREAM_SEEK_CUR, NULL));
  96. ULISet32(uliSize, STREAMSIZE);
  97. IllResult("SetSize on read-only stream",
  98. pstm->SetSize(uliSize));
  99. ULISet32(uliPos, 0);
  100. ULISet32(cb, STREAMSIZE);
  101. IllResult("LockRegion attempt",
  102. pstm->LockRegion(uliPos, cb, LOCK_ONLYONCE));
  103. IllResult("UnlockRegion attempt",
  104. pstm->UnlockRegion(uliPos, cb, LOCK_ONLYONCE));
  105. pwstm->Unwrap();
  106. pwstg->Unwrap();
  107. }
  108. void i_enum(void)
  109. {
  110. WStorage *pwstg;
  111. IStorage *pstg;
  112. IEnumSTATSTG *penm;
  113. WStgCreateDocfile(DRTDF, ROOTP(STGM_READWRITE), 0, &pwstg);
  114. pstg = pwstg->GetI();
  115. IllResult("EnumElements with NULL ppenm",
  116. pstg->EnumElements(0, NULL, 0, NULL));
  117. IllResult("EnumElements with non-zero reserved1",
  118. pstg->EnumElements(1, NULL, 0, &penm));
  119. IllResult("EnumElements with non-zero reserved2",
  120. pstg->EnumElements(0, (void *)1, 0, &penm));
  121. IllResult("EnumElements with non-zero reserved3",
  122. pstg->EnumElements(0, NULL, 1, &penm));
  123. pwstg->Unwrap();
  124. }