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.

107 lines
2.7 KiB

  1. // Repro case for LKRhash Clear bug
  2. #include <windows.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include "MinFan.h"
  7. void
  8. test(
  9. int N)
  10. {
  11. printf("\nTest driver for LKRhash for wchar, %d\n", N);
  12. // A case-senstive string-to-int map
  13. CWcharHashTable map;
  14. int index;
  15. LK_RETCODE lkrc;
  16. #ifdef LKR_DEPRECATED_ITERATORS
  17. CWcharHashTable::CIterator iter;
  18. #endif // LKR_DEPRECATED_ITERATORS
  19. #if 1
  20. // Some objects for the hash tables
  21. printf("\tFirst Insertion Loop\n");
  22. for ( index = 0; index < N; index++)
  23. {
  24. char buf[30];
  25. sprintf(buf, "page%04d.htm", index);
  26. VwrecordBase* psoRecord = new VwrecordBase(buf, index);
  27. // printf("Insert1: pso is %s\n", psoRecord->getKey());
  28. map.InsertRecord(psoRecord);
  29. }
  30. #endif
  31. #ifdef LKR_DEPRECATED_ITERATORS
  32. printf("\tFirst Iteration Loop\n");
  33. for (lkrc = map.InitializeIterator(&iter);
  34. lkrc == LK_SUCCESS;
  35. lkrc = map.IncrementIterator(&iter))
  36. {
  37. const VwrecordBase* psoRecord = iter.Record();
  38. // printf("Iterate1: pso is %s\n", psoRecord->getKey());
  39. }
  40. lkrc = map.CloseIterator(&iter);
  41. #endif // LKR_DEPRECATED_ITERATORS
  42. printf("\tAfter insertions, size of map is %d\n", map.Size());
  43. map.Clear();
  44. printf("\tAfter Clear(), size of map is %d\n", map.Size());
  45. printf("\tSecond Insertion Loop\n");
  46. for ( index = 0; index < N; index++)
  47. {
  48. char buf[30];
  49. sprintf(buf, "page%4d", index);
  50. VwrecordBase* psoRecord = new VwrecordBase(buf, index);
  51. // printf("Insert2: pso is %s\n", psoRecord->getKey());
  52. map.InsertRecord(psoRecord);
  53. const VwrecordBase* psoRecord2;
  54. lkrc = map.FindKey(buf, &psoRecord2);
  55. // printf("FindKey(%s) returned %d, %p\n", buf, lkrc, psoRecord2);
  56. map.AddRefRecord(psoRecord2, LKAR_EXPLICIT_RELEASE);
  57. }
  58. #ifdef LKR_DEPRECATED_ITERATORS
  59. printf("\tSecond Iteration Loop\n");
  60. for (index = 0, lkrc = map.InitializeIterator(&iter);
  61. lkrc == LK_SUCCESS;
  62. ++index, lkrc = map.IncrementIterator(&iter))
  63. {
  64. const VwrecordBase* psoRecord = iter.Record();
  65. // printf("Iterate2: %d, pso is %s\n", index, psoRecord->getKey());
  66. }
  67. lkrc = map.CloseIterator(&iter);
  68. #endif // LKR_DEPRECATED_ITERATORS
  69. printf("\tClearing again\n");
  70. map.Clear();
  71. printf("\tFinishing %d\n", N);
  72. }
  73. int __cdecl
  74. main(
  75. int argc,
  76. char **argv)
  77. {
  78. #if 0
  79. for (int i = 0; i < 200000; ++i)
  80. test(i);
  81. #endif
  82. int N = 5092;
  83. if (argc > 1)
  84. N = atoi(argv[1]);
  85. test(N);
  86. return 0;
  87. }