stylesheet_test.C 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: stylesheet_test.cc /main/4 1996/07/18 16:03:49 drk $ */
  24. #ifdef REGRESSION_TEST
  25. #include "oliasdb/stylesheet_test.h"
  26. #define LARGE_BUFSIZ 2048
  27. void print_stylesheet(stylesheet_smart_ptr& x, ostream& out)
  28. {
  29. out << "name=" << x.name();
  30. out << "online_data_size=" << x.online_data_size();
  31. out << "online_data=" << x.online_data();
  32. out << "hardcopy_data_size=" << x.hardcopy_data_size();
  33. out << "hardcopy_data_size=" << x.hardcopy_data();
  34. }
  35. int compare_stylesheet(stylesheet_smart_ptr& pattern, info_base* base_ptr)
  36. {
  37. char pattern_buf[LARGE_BUFSIZ];
  38. ostringstream pattern_out(pattern_buf, LARGE_BUFSIZ, ios::out);
  39. print_stylesheet(pattern, pattern_out);
  40. char loc[BUFSIZ];
  41. int len = MIN(strlen(pattern.name()), BUFSIZ - 1);
  42. *((char *) memcpy(loc, pattern.name(), len) + len) = '\0';
  43. stylesheet_smart_ptr x( base_ptr, loc );
  44. char db_buf[LARGE_BUFSIZ];
  45. ostringstream db_out(db_buf, LARGE_BUFSIZ, ios::out);
  46. print_stylesheet(x, db_out);
  47. return compare_stream(pattern_out, db_out);
  48. }
  49. void update_stylesheet_test(char* filename, info_base* base_ptr, char* locator)
  50. {
  51. char buf[LBUFSIZ];
  52. char st_buf[LBUFSIZ];
  53. fstream in(filename, ios::in);
  54. while (in) {
  55. in.getline(buf, LBUFSIZ);
  56. int slen = strlen(st_buf);
  57. int len = MIN(strlen(buf), LBUFSIZ - 1 - slen);
  58. *((char *) memcpy(st_buf + slen, buf, len) + len) = '\0';
  59. }
  60. stylesheet_smart_ptr st(base_ptr, locator);
  61. st.update_online_data(st_buf, strlen(st_buf));
  62. }
  63. int stylesheet_test_loc( info_lib* infolib_ptr, const char* base_name, const char* loc )
  64. {
  65. stylesheet_smart_ptr x( infolib_ptr, base_name, loc );
  66. cerr << form("info of stylesheet object with loc %s:\n", loc);
  67. print_stylesheet(x, cerr);
  68. return 0;
  69. }
  70. int stylesheet_test_oid( info_lib* infolib_ptr, const char* base_name, const char* oid_str)
  71. {
  72. oid_t id((char*)oid_str, true, false);
  73. stylesheet_smart_ptr x( infolib_ptr, base_name, id );
  74. cerr << form("info of stylesheet object with id : ");
  75. debug(cerr, id);
  76. debug(cerr, x.name());
  77. debug(cerr, x.online_data_size());
  78. debug(cerr, x.online_data());
  79. debug(cerr, x.hardcopy_data_size());
  80. debug(cerr, x.hardcopy_data());
  81. x.its_oid().asciiOut(cerr); cerr << "\n";
  82. return 0;
  83. }
  84. void generate_stylesheet_instance(random_gen& x, ostream& out, int min_len, int max_len)
  85. {
  86. out << "1011\n";
  87. out << "3\n";
  88. x.random_string(out, 15, 15); // name
  89. x.random_string(out, min_len, max_len); // sheet1
  90. x.random_string(out, min_len, max_len); // sheet2
  91. }
  92. #endif