test_columns.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /****************************************************************************
  2. *
  3. * MODULE: test.dbmi_base.lib
  4. *
  5. * AUTHOR(S): Original author
  6. * Soeren Gebbert soerengebbert <at> googlemail <dot> com
  7. * 2010 Braunschweig, Germany
  8. *
  9. * PURPOSE: Unit and integration tests for the dbmi_base library
  10. *
  11. * COPYRIGHT: (C) 2007 by the GRASS Development Team
  12. *
  13. * This program is free software under the GNU General Public
  14. * License (>=v2). Read the file COPYING that comes with GRASS
  15. * for details.
  16. *
  17. *****************************************************************************/
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <grass/gis.h>
  22. #include <grass/glocale.h>
  23. #include <grass/dbmi.h>
  24. #include "test_dbmi_base_lib.h"
  25. /* prototypes */
  26. static int test_copy_column(void);
  27. /* ************************************************************************* */
  28. /* Performe the column unit tests ****************************************** */
  29. /* ************************************************************************* */
  30. int unit_test_column(void)
  31. {
  32. int sum = 0;
  33. G_message(_("\n++ Running column unit tests ++"));
  34. sum += test_copy_column();
  35. if (sum > 0)
  36. G_warning(_("\n-- column unit tests failure --"));
  37. else
  38. G_message(_("\n-- column unit tests finished successfully --"));
  39. return sum;
  40. }
  41. /* *************************************************************** */
  42. /* Test copy dbColumn functionality ****************************** */
  43. /* *************************************************************** */
  44. int test_copy_column(void)
  45. {
  46. int sum = 0;
  47. dbColumn *column, *c2;
  48. G_message(_("\n++ Run test copy column ++"));
  49. /*Test the set and copy function*/
  50. column = (dbColumn*)db_calloc(sizeof(dbColumn), 2);
  51. db_init_column(&column[0]);
  52. db_init_column(&column[1]);
  53. /*Write some initial values*/
  54. db_set_value_double(&column[0].defaultValue, 0.5);
  55. db_set_value_double(&column[0].value, 10.5);
  56. db_set_column_description(&column[0], "Test column");
  57. db_set_column_host_type(&column[0], 1);
  58. db_set_column_length(&column[0], 8);
  59. db_set_column_name(&column[0], "test");
  60. db_set_column_null_allowed(&column[0]);
  61. db_set_column_precision(&column[0], 20);
  62. db_set_column_scale(&column[0], 1);
  63. db_set_column_select_priv_granted(&column[0]);
  64. db_set_column_sqltype(&column[0], DB_SQL_TYPE_DOUBLE_PRECISION);
  65. db_set_column_select_priv_granted(&column[0]);
  66. db_set_column_update_priv_granted(&column[0]);
  67. db_set_column_use_default_value(&column[0]);
  68. /*Copy the column*/
  69. db_copy_column(&column[1], &column[0]);
  70. c2 = db_copy_column(NULL, &column[1]);
  71. fprintf(stdout, "##### First column:\n");
  72. db_print_column_definition(stdout, &column[0]);
  73. fprintf(stdout, "##### Second column:\n");
  74. db_print_column_definition(stdout, &column[1]);
  75. fprintf(stdout, "##### Third column:\n");
  76. db_print_column_definition(stdout, c2);
  77. /*Compare the columns*/
  78. if(strcmp(column[0].columnName.string, c2->columnName.string) != 0) {
  79. G_warning("Error copying column name");
  80. sum++;
  81. }
  82. if(strcmp(column[0].description.string, c2->description.string) != 0) {
  83. G_warning("Error copying column description");
  84. sum++;
  85. }
  86. if(column[0].dataLen != c2->dataLen) {
  87. G_warning("Error copying dataLen");
  88. sum++;
  89. }
  90. if(column[0].defaultValue.d != c2->defaultValue.d) {
  91. G_warning("Error copying default value");
  92. sum++;
  93. }
  94. if(column[0].hasDefaultValue != c2->hasDefaultValue) {
  95. G_warning("Error copying hasDefaultValue");
  96. sum++;
  97. }
  98. if(column[0].hostDataType != column[1].hostDataType) {
  99. G_warning("Error copying hostDataType");
  100. sum++;
  101. }
  102. if(column[0].nullAllowed != c2->nullAllowed) {
  103. G_warning("Error copying nullAllowed");
  104. sum++;
  105. }
  106. if(column[0].precision != c2->precision) {
  107. G_warning("Error copying precision");
  108. sum++;
  109. }
  110. if(column[0].scale != c2->scale) {
  111. G_warning("Error copying scale");
  112. sum++;
  113. }
  114. if(column[0].select != c2->select) {
  115. G_warning("Error copying select");
  116. sum++;
  117. }
  118. if(column[0].sqlDataType != c2->sqlDataType) {
  119. G_warning("Error copying sqlDataType");
  120. sum++;
  121. }
  122. if(column[0].update != c2->update) {
  123. G_warning("Error copying update");
  124. sum++;
  125. }
  126. if(column[0].useDefaultValue != c2->useDefaultValue) {
  127. G_warning("Error copying useDefaultValue");
  128. sum++;
  129. }
  130. if(column[0].value.d != c2->value.d) {
  131. G_warning("Error copying value");
  132. sum++;
  133. }
  134. G_message(_("\n++ Test copy column finished ++"));
  135. return sum;
  136. }