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.

105 lines
2.3 KiB

  1. #include <nt.h>
  2. #include <ntrtl.h>
  3. #include <nturtl.h>
  4. #include <windows.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #define POOL_TYPE ULONG
  9. #include "defs.h"
  10. #include "dict.h"
  11. typedef struct _TEST_ENTRY {
  12. ULONG Unused;
  13. ULONG Key;
  14. STOR_DICTIONARY_ENTRY Link;
  15. } TEST_ENTRY, *PTEST_ENTRY;
  16. PVOID
  17. WINAPI
  18. TestGetKey(
  19. IN PSTOR_DICTIONARY_ENTRY Entry
  20. )
  21. {
  22. return (PVOID)(CONTAINING_RECORD (Entry, TEST_ENTRY, Link)->Key);
  23. }
  24. void __cdecl main()
  25. {
  26. STOR_DICTIONARY Dict;
  27. PTEST_ENTRY Entry;
  28. LONG i;
  29. NTSTATUS Status;
  30. PSTOR_DICTIONARY_ENTRY Link;
  31. Status = StorCreateDictionary (&Dict,
  32. 1,
  33. 0,
  34. TestGetKey,
  35. NULL,
  36. NULL);
  37. if (!NT_SUCCESS (Status)) {
  38. printf ("Failed to create dictionary!\n");
  39. exit (1);
  40. }
  41. //
  42. // Insert 1000 elements, verifying they were successfully
  43. // inserted.
  44. //
  45. for (i = 0; i < 1000; i++) {
  46. Entry = malloc (sizeof (TEST_ENTRY));
  47. RtlZeroMemory (Entry, sizeof (TEST_ENTRY));
  48. Entry->Key = i;
  49. Status = StorInsertDictionary (&Dict, &Entry->Link);
  50. ASSERT (Status == STATUS_SUCCESS);
  51. Status = StorFindDictionary (&Dict, (PVOID)i, NULL);
  52. ASSERT (Status == STATUS_SUCCESS);
  53. }
  54. //
  55. // Test that they we cannot insert any more items with the same key.
  56. //
  57. for (i = 0; i < 1000; i++) {
  58. Entry = malloc (sizeof (TEST_ENTRY));
  59. RtlZeroMemory (Entry, sizeof (TEST_ENTRY));
  60. Entry->Key = i;
  61. Status = StorInsertDictionary (&Dict, &Entry->Link);
  62. ASSERT (!NT_SUCCESS (Status));
  63. free (Entry);
  64. }
  65. //
  66. // Remove all items, one at a time.
  67. //
  68. for (i = 999; i >= 0; i--) {
  69. Status = StorRemoveDictionary (&Dict, (PVOID)i, &Link);
  70. ASSERT (Status == STATUS_SUCCESS);
  71. Entry = CONTAINING_RECORD (Link, TEST_ENTRY, Link);
  72. ASSERT (Entry->Key == i);
  73. free (Entry);
  74. }
  75. //
  76. // Verify that there are no more items.
  77. //
  78. ASSERT (StorGetDictionaryCount (&Dict) == 0);
  79. }