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.

162 lines
4.9 KiB

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