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.

102 lines
2.3 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. }
  54. #ifdef LKR_DEPRECATED_ITERATORS
  55. printf("\tSecond Iteration Loop\n");
  56. for (index = 0, lkrc = map.InitializeIterator(&iter);
  57. lkrc == LK_SUCCESS;
  58. ++index, lkrc = map.IncrementIterator(&iter))
  59. {
  60. const VwrecordBase* psoRecord = iter.Record();
  61. // printf("Iterate2: %d, pso is %s\n", index, psoRecord->getKey());
  62. }
  63. lkrc = map.CloseIterator(&iter);
  64. #endif // LKR_DEPRECATED_ITERATORS
  65. printf("\tClearing again\n");
  66. map.Clear();
  67. printf("\tFinishing %d\n", N);
  68. }
  69. int __cdecl
  70. main(
  71. int argc,
  72. char **argv)
  73. {
  74. #if 0
  75. for (int i = 0; i < 200000; ++i)
  76. test(i);
  77. #endif
  78. int N = 5092;
  79. if (argc > 1)
  80. N = atoi(argv[1]);
  81. test(N);
  82. return 0;
  83. }