testhash.cxx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*=========================================================================
  2. Program: KWSys - Kitware System Library
  3. Module: $RCSfile$
  4. Copyright (c) Kitware, Inc., Insight Consortium. All rights reserved.
  5. See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even
  7. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  8. PURPOSE. See the above copyright notices for more information.
  9. =========================================================================*/
  10. #include "kwsysPrivate.h"
  11. #include KWSYS_HEADER(hash_map.hxx)
  12. #include KWSYS_HEADER(hash_set.hxx)
  13. #include KWSYS_HEADER(ios/iostream)
  14. // Work-around CMake dependency scanning limitation. This must
  15. // duplicate the above list of headers.
  16. #if 0
  17. # include "hash_map.hxx.in"
  18. # include "hash_set.hxx.in"
  19. # include "hashtable.hxx.in"
  20. # include "kwsys_ios_iostream.h.in"
  21. #endif
  22. #if defined(_MSC_VER)
  23. # pragma warning (disable:4786)
  24. #endif
  25. #if defined(__sgi) && !defined(__GNUC__)
  26. # pragma set woff 1468 /* inline function cannot be explicitly instantiated */
  27. #endif
  28. template class kwsys::hash_map<const char*, int>;
  29. template class kwsys::hash_set<int>;
  30. bool test_hash_map()
  31. {
  32. typedef kwsys::hash_map<const char*, int> mtype;
  33. mtype m;
  34. const char* keys[] = {"hello", "world"};
  35. m[keys[0]] = 1;
  36. m.insert(mtype::value_type(keys[1], 2));
  37. int sum = 0;
  38. for(mtype::iterator mi = m.begin(); mi != m.end(); ++mi)
  39. {
  40. kwsys_ios::cout << "Found entry [" << mi->first << "," << mi->second << "]"
  41. << kwsys_ios::endl;
  42. sum += mi->second;
  43. }
  44. return sum == 3;
  45. }
  46. bool test_hash_set()
  47. {
  48. typedef kwsys::hash_set<int> stype;
  49. stype s;
  50. s.insert(1);
  51. s.insert(2);
  52. int sum = 0;
  53. for(stype::iterator si = s.begin(); si != s.end(); ++si)
  54. {
  55. kwsys_ios::cout << "Found entry [" << *si << "]" << kwsys_ios::endl;
  56. sum += *si;
  57. }
  58. return sum == 3;
  59. }
  60. int main()
  61. {
  62. bool result = true;
  63. result = test_hash_map() && result;
  64. result = test_hash_set() && result;
  65. return result? 0:1;
  66. }