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.

306 lines
5.9 KiB

  1. /*++
  2. Copyright (c) 1991-1999, Microsoft Corporation All rights reserved.
  3. Module Name:
  4. esgitest.c
  5. Abstract:
  6. Test module for NLS API EnumSystemGeoID.
  7. NOTE: This code was simply hacked together quickly in order to
  8. test the different code modules of the NLS component.
  9. This is NOT meant to be a formal regression test.
  10. Revision History:
  11. 09-12-2000 JulieB Created.
  12. --*/
  13. //
  14. // Include Files.
  15. //
  16. #include "nlstest.h"
  17. //
  18. // Constant Declarations.
  19. //
  20. #define ESGI_INVALID_FLAG 3
  21. #define NUM_SUPPORTED_GEOIDS 260
  22. //
  23. // Global Variables.
  24. //
  25. int GeoCtr;
  26. int EnumErrors;
  27. //
  28. // Forward Declarations.
  29. //
  30. BOOL
  31. InitEnumSystemGeoID();
  32. int
  33. ESGI_BadParamCheck();
  34. int
  35. ESGI_NormalCase();
  36. BOOL
  37. CALLBACK
  38. MyFuncGeo(
  39. GEOID GeoId);
  40. //
  41. // Callback function.
  42. //
  43. BOOL CALLBACK MyFuncGeo(
  44. GEOID GeoId)
  45. {
  46. TCHAR pData[128];
  47. pData[0] = 0;
  48. if (GetGeoInfoW( GeoId,
  49. GEO_FRIENDLYNAME,
  50. pData,
  51. sizeof(pData) / sizeof(TCHAR),
  52. 0 ) == 0)
  53. {
  54. printf("GetGeoInfo failed during Enum for GeoId %d\n", GeoId);
  55. EnumErrors++;
  56. }
  57. else if (pData[0] == 0)
  58. {
  59. printf("GetGeoInfo returned null string during Enum for GeoId %d\n", GeoId);
  60. EnumErrors++;
  61. }
  62. if (Verbose)
  63. {
  64. printf("%d - %ws\n", GeoId, pData);
  65. }
  66. GeoCtr++;
  67. return (TRUE);
  68. }
  69. ////////////////////////////////////////////////////////////////////////////
  70. //
  71. // TestEnumSystemGeoID
  72. //
  73. // Test routine for EnumSystemGeoID API.
  74. //
  75. // 09-12-00 JulieB Created.
  76. ////////////////////////////////////////////////////////////////////////////
  77. int TestEnumSystemGeoID()
  78. {
  79. int ErrCount = 0; // error count
  80. //
  81. // Print out what's being done.
  82. //
  83. printf("\n\nTESTING EnumSystemGeoID...\n\n");
  84. //
  85. // Initialize global variables.
  86. //
  87. if (!InitEnumSystemGeoID())
  88. {
  89. printf("\nABORTED TestEnumSystemGeoID: Could not Initialize.\n");
  90. return (1);
  91. }
  92. //
  93. // Test bad parameters.
  94. //
  95. ErrCount += ESGI_BadParamCheck();
  96. //
  97. // Test normal cases.
  98. //
  99. ErrCount += ESGI_NormalCase();
  100. //
  101. // Print out result.
  102. //
  103. printf("\nEnumSystemGeoID: ERRORS = %d\n", ErrCount);
  104. //
  105. // Return total number of errors found.
  106. //
  107. return (ErrCount);
  108. }
  109. ////////////////////////////////////////////////////////////////////////////
  110. //
  111. // InitEnumSystemGeoID
  112. //
  113. // This routine initializes the global variables. If no errors were
  114. // encountered, then it returns TRUE. Otherwise, it returns FALSE.
  115. //
  116. // 09-12-00 JulieB Created.
  117. ////////////////////////////////////////////////////////////////////////////
  118. BOOL InitEnumSystemGeoID()
  119. {
  120. //
  121. // Initialize geo counter.
  122. //
  123. GeoCtr = 0;
  124. //
  125. // Initialize enum error counter.
  126. //
  127. EnumErrors = 0;
  128. //
  129. // Return success.
  130. //
  131. return (TRUE);
  132. }
  133. ////////////////////////////////////////////////////////////////////////////
  134. //
  135. // ESGI_BadParamCheck
  136. //
  137. // This routine passes in bad parameters to the API routines and checks to
  138. // be sure they are handled properly. The number of errors encountered
  139. // is returned to the caller.
  140. //
  141. // 09-12-00 JulieB Created.
  142. ////////////////////////////////////////////////////////////////////////////
  143. int ESGI_BadParamCheck()
  144. {
  145. int NumErrors = 0; // error count - to be returned
  146. int rc; // return code
  147. //
  148. // Invalid Function.
  149. //
  150. // Variation 1 - Function = invalid
  151. GeoCtr = 0;
  152. EnumErrors = 0;
  153. rc = EnumSystemGeoID(GEOCLASS_NATION, 0, NULL);
  154. NumErrors += EnumErrors;
  155. CheckReturnBadParamEnum( rc,
  156. FALSE,
  157. ERROR_INVALID_PARAMETER,
  158. "Function invalid",
  159. &NumErrors,
  160. GeoCtr,
  161. 0 );
  162. //
  163. // Invalid Flag.
  164. //
  165. // Variation 1 - dwFlags = invalid
  166. GeoCtr = 0;
  167. EnumErrors = 0;
  168. rc = EnumSystemGeoID(ESGI_INVALID_FLAG, 0, MyFuncGeo);
  169. NumErrors += EnumErrors;
  170. CheckReturnBadParamEnum( rc,
  171. FALSE,
  172. ERROR_INVALID_FLAGS,
  173. "Flag invalid",
  174. &NumErrors,
  175. GeoCtr,
  176. 0 );
  177. // Variation 2 - dwFlags = invalid 2
  178. GeoCtr = 0;
  179. EnumErrors = 0;
  180. rc = EnumSystemGeoID(GEOCLASS_REGION, 0, MyFuncGeo);
  181. NumErrors += EnumErrors;
  182. CheckReturnBadParamEnum( rc,
  183. FALSE,
  184. ERROR_INVALID_FLAGS,
  185. "Flag invalid 2",
  186. &NumErrors,
  187. GeoCtr,
  188. 0 );
  189. //
  190. // NOTE: There is no validation on ParentGeoId. This parameter
  191. // isn't used.
  192. //
  193. //
  194. // Return total number of errors found.
  195. //
  196. return (NumErrors);
  197. }
  198. ////////////////////////////////////////////////////////////////////////////
  199. //
  200. // ESGI_NormalCase
  201. //
  202. // This routine tests the normal cases of the API routine.
  203. //
  204. // 09-12-00 JulieB Created.
  205. ////////////////////////////////////////////////////////////////////////////
  206. int ESGI_NormalCase()
  207. {
  208. int NumErrors = 0; // error count - to be returned
  209. int rc; // return code
  210. // Variation 1 - Installed
  211. GeoCtr = 0;
  212. EnumErrors = 0;
  213. rc = EnumSystemGeoID(GEOCLASS_NATION, 0, MyFuncGeo);
  214. NumErrors += EnumErrors;
  215. CheckReturnValidEnum( rc,
  216. TRUE,
  217. GeoCtr,
  218. NUM_SUPPORTED_GEOIDS,
  219. "GeoClass Nation",
  220. &NumErrors );
  221. //
  222. // Return total number of errors found.
  223. //
  224. return (NumErrors);
  225. }