PQTest.C 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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: PQTest.cc /main/3 1996/06/11 17:07:26 cde-hal $
  24. #include <iostream>
  25. using namespace std;
  26. #include "SymTab.h"
  27. #include "PathQualifier.h"
  28. #include "Element.h"
  29. #include "Attribute.h"
  30. #include "AttributeList.h"
  31. void
  32. styleerror(char *)
  33. {
  34. // bogus
  35. abort();
  36. }
  37. class Renderer;
  38. Renderer *gRenderer = 0;
  39. main()
  40. {
  41. SymbolTable symtab ;
  42. Attribute *attr1a = new Attribute(symtab.intern("attr1a"),"one-a");
  43. Attribute *attr1b = new Attribute(symtab.intern("attr1b"),"one-b");
  44. AttributeList *alist1 = new AttributeList ;
  45. alist1->add(attr1a);
  46. alist1->add(attr1b);
  47. Element one(symtab.intern("One"), 1, alist1, 0);
  48. Element two(symtab.intern("Two"), 2, 0, 0);
  49. PQPosition posn_eq(PQEqual, 1);
  50. PQPosition posn_neq(PQNotEqual, 1);
  51. // /////////////////////////////////////////////////////////////////////////
  52. // Test Position
  53. // /////////////////////////////////////////////////////////////////////////
  54. /* -------- Test Position Equal -------- */
  55. cout << posn_eq.evaluate (one) << endl; // 1
  56. cout << posn_eq.evaluate (two) << endl; // 0
  57. cout << "---" << endl;
  58. /* -------- Test Position Not Equal -------- */
  59. cout << posn_neq.evaluate (one) << endl; // 0
  60. cout << posn_neq.evaluate (two) << endl; // 1
  61. cout << "---" << endl;
  62. // ///////////////////////////////////////////////////////////////////////
  63. // Test Attribute Comparison
  64. // ///////////////////////////////////////////////////////////////////////
  65. PQAttributeSelector pqas_eqa(symtab.intern("attr1a"), PQEqual, "one-a");
  66. PQAttributeSelector pqas_eqb(symtab.intern("attr1a"), PQEqual, "one-b");
  67. PQAttributeSelector pqas_neqa(symtab.intern("attr1a"), PQNotEqual, "one-a");
  68. PQAttributeSelector pqas_neqb(symtab.intern("attr1a"), PQNotEqual, "one-b");
  69. PQAttributeSelector pqas_eqa2(symtab.intern("attr2a"), PQEqual, "one-a");
  70. PQAttributeSelector pqas_eqb2(symtab.intern("attr2a"), PQEqual, "one-b");
  71. PQAttributeSelector pqas_neqa2(symtab.intern("attr2a"), PQNotEqual, "one-a");
  72. PQAttributeSelector pqas_neqb2(symtab.intern("attr2a"), PQNotEqual, "one-b");
  73. cout << pqas_eqa.evaluate(one) << endl ; // 1
  74. cout << pqas_eqa.evaluate(two) << endl ; // 0
  75. cout << pqas_eqb.evaluate(one) << endl ; // 0
  76. cout << pqas_eqb.evaluate(two) << endl ; // 0
  77. cout << pqas_neqa.evaluate(one) << endl ; // 0
  78. cout << pqas_neqa.evaluate(two) << endl ; // 1
  79. cout << pqas_neqb.evaluate(one) << endl ; // 1
  80. cout << pqas_neqb.evaluate(two) << endl ; // 1
  81. cout << pqas_eqa2.evaluate(one) << endl ; // 0
  82. cout << pqas_eqa2.evaluate(two) << endl ; // 0
  83. cout << pqas_eqb2.evaluate(one) << endl ; // 0
  84. cout << pqas_eqb2.evaluate(two) << endl ; // 0
  85. cout << pqas_neqa2.evaluate(one) << endl ; // 1
  86. cout << pqas_neqa2.evaluate(two) << endl ; // 1
  87. cout << pqas_neqb2.evaluate(one) << endl ; // 1
  88. cout << pqas_neqb2.evaluate(two) << endl ; // 1
  89. cout << "****" << endl;
  90. // ///////////////////////////////////////////////////////////////////////
  91. // composite
  92. // ///////////////////////////////////////////////////////////////////////
  93. // position = 1 and attr(attr1a) == "one-a"
  94. PQPosition *p1 = new PQPosition(PQEqual, 1);
  95. PQAttributeSelector *a1 = new PQAttributeSelector(symtab.intern("attr1a"),
  96. PQEqual, "one-a");
  97. PQAttributeSelector *a2 = new PQAttributeSelector(symtab.intern("attr1a"),
  98. PQEqual, "value");
  99. PQLogExpr l1 (p1, PQand, a1);
  100. PQLogExpr l2 (p1, PQor, a1);
  101. PQLogExpr l3 (p1, PQand, a2);
  102. PQLogExpr l4 (p1, PQor, a2);
  103. cout << l1.evaluate(one) << endl ; // 1
  104. cout << l1.evaluate(two) << endl ; // 0
  105. cout << l2.evaluate(one) << endl ; // 1
  106. cout << l2.evaluate(two) << endl ; // 0
  107. cout << l3.evaluate(one) << endl ; // 0
  108. cout << l3.evaluate(two) << endl ; // 0
  109. cout << l4.evaluate(one) << endl ; // 1
  110. cout << l4.evaluate(two) << endl ; // 0
  111. cout << "..." << endl;
  112. cout << PQNot(&l4).evaluate(one) << endl ; // 0
  113. cout << PQNot(&l4).evaluate(two) << endl ; // 1
  114. }