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.

148 lines
4.8 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. #pragma warning(disable:4245)
  94. // LISet32 in objbase.h has a bug that issues warning for negative values
  95. LISet32(liSeek, -1);
  96. #pragma warning(default:4245)
  97. IllResult("Seek before beginning",
  98. pstm->Seek(liSeek, STREAM_SEEK_CUR, NULL));
  99. ULISet32(uliSize, STREAMSIZE);
  100. IllResult("SetSize on read-only stream",
  101. pstm->SetSize(uliSize));
  102. ULISet32(uliPos, 0);
  103. ULISet32(cb, STREAMSIZE);
  104. IllResult("LockRegion attempt",
  105. pstm->LockRegion(uliPos, cb, LOCK_ONLYONCE));
  106. IllResult("UnlockRegion attempt",
  107. pstm->UnlockRegion(uliPos, cb, LOCK_ONLYONCE));
  108. pwstm->Unwrap();
  109. pwstg->Unwrap();
  110. }
  111. void i_enum(void)
  112. {
  113. WStorage *pwstg;
  114. IStorage *pstg;
  115. IEnumSTATSTG *penm;
  116. WStgCreateDocfile(DRTDF, ROOTP(STGM_READWRITE), 0, &pwstg);
  117. pstg = pwstg->GetI();
  118. IllResult("EnumElements with NULL ppenm",
  119. pstg->EnumElements(0, NULL, 0, NULL));
  120. IllResult("EnumElements with non-zero reserved1",
  121. pstg->EnumElements(1, NULL, 0, &penm));
  122. IllResult("EnumElements with non-zero reserved2",
  123. pstg->EnumElements(0, (void *)1, 0, &penm));
  124. IllResult("EnumElements with non-zero reserved3",
  125. pstg->EnumElements(0, NULL, 1, &penm));
  126. pwstg->Unwrap();
  127. }