summaryrefslogtreecommitdiff
path: root/tests/testhyperwave
blob: 973489cf345270eb1d119f9ddaa1bc20475ea5dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?
  $id = 190867;       // A plain/text document
  $collid = 169828;   // A collection
  $query = "Name=m*";      // Search query for test_9
  $host = "gehtnix";
  $username = "steinm";
  $password = "akli9132";

  $connect = hw_connect($host, 418, $username, $password);
  if(hw_error($connect)) {
    echo "ERROR: ".hw_errormsg($connect)."\n";
    exit;
  }

  // Set all test to 'yes' if they shall be executed
  $test_1 = "yes";    // Get the text document with id $id and output it
  $test_2 = "yes";    // Check if id $id is in $collid
  $test_3 = "yes";   // Convert object record to object array and back
  $test_4 = "yes";   // Get object record of object with id $id
  $test_5 = "yes";   // List children of $collid
  $test_6 = "yes";   // List parents of $id
  $test_7 = "yes";   // Insert a new text document
  $test_8 = "yes";   // Remove the just inserted text document
  $test_9 = "yes";   // Searching for objects with Name $query

  /* Lists an object array
  */
  function list_attr($attributes) {
    global $imagepath;
    for($i=0; $i<count($attributes); $i++) {
      $key = key($attributes);
      switch($key) {
        case "Title":
        case "Description":
          $title_arr = $attributes[$key];
          $cj = count($title_arr);
          printf("%s = ", $key);
          for($j=0; $j<$cj; $j++) {
            $tkey = key($title_arr);
            switch($tkey) {
              case "en":
                $flagfile = "english.gif";
                break;
              case "ge":
                $flagfile = "german.gif";
                break;
              case "du":
                $flagfile = "dutch.gif";
                break;
              default:
                $flagfile = "europe.gif";
            }
            printf("%s:%s; ", $tkey, $title_arr[$tkey]);

            next($title_arr);
          }
          printf("\n");
          break;
        default:
          printf("%s = %s\n", $key, $attributes[$key]);
        }
      next($attributes);
      }
    echo "\n";
  }

  // Here come the tests
  if($test_1 == "yes") {
    echo "TEST 1 ----------------------------------------------\n";
    echo "Get the text document with id 0x".dechex($id)."\n";
    $doc = hw_gettext($connect, $id);
    if(hw_error($connect)) {
      echo "ERROR: ".hw_errormsg($connect)."\n";
      exit;
    }
    hw_output_document($doc);
    echo "\n";
  }

  if($test_2 == "yes") {
    echo "TEST 2 ----------------------------------------------\n";
    echo "Checking if '$id' (0x".dechex($id).") is in collection '$collid (0x".dechex($collid).")'\n";
    $incoll = hw_incollections($connect, array($id), array($collid), 0);
    if(hw_error($connect)) {
      echo "ERROR: ".hw_errormsg($connect)."\n";
      exit;
    }
    for($i=0; $i<count($incoll); $i++)
      echo $incoll[$i]."\n";
  }

  if($test_3 == "yes") {
    echo "TEST 3 ----------------------------------------------\n";
    echo "Convert an object array into an object record\n";
    $objrec = hw_array2objrec(array("Title"=>"ge:Hier der Titel", "Author"=>"Hier der Autor"));
    echo $objrec."\n";
    $objrec .= "\nTitle=en:Here the title";
    echo "Add another title and convert it back to an object array\n";
    $objarr = hw_objrec2array($objrec);
    list_attr($objarr);
  }

  if($test_4 == "yes") {
    echo "TEST 4 ----------------------------------------------\n";
    echo "Get the object array of document with id 0x".dechex($id)."\n";
    $objrec = hw_getobject($connect, $id);
    if(hw_error($connect)) {
      echo "ERROR: ".hw_errormsg($connect)."\n";
      exit;
    }
    $objarr = hw_objrec2array($objrec);
    list_attr($objarr);
  }

  if($test_5 == "yes") {
    echo "TEST 5 ----------------------------------------------\n";
    echo "List the children of collection 0x".dechex($collid)."\n";
    $children = hw_childrenobj($connect, $collid);
    if(hw_error($connect)) {
      echo "ERROR: ".hw_errormsg($connect)."\n";
      exit;
    }
    $c_children = count($children) - 1;
    for($i=0; $i<$c_children; $i++) {
      $objarr = hw_objrec2array($children[$i]);
      list_attr($objarr);
    }
    list_attr($children[$c_children]);
  }

  if($test_6 == "yes") {
    echo "TEST 6 ----------------------------------------------\n";
    echo "List the parents of object 0x".dechex($id)."\n";
    $parents = hw_getparentsobj($connect, $collid);
    if(hw_error($connect)) {
      echo "ERROR: ".hw_errormsg($connect)."\n";
      exit;
    }
    $c_parents = count($parents) - 1;
    for($i=0; $i<$c_parents; $i++) {
      $objarr = hw_objrec2array($parents[$i]);
      list_attr($objarr);
    }
    list_attr($parents[$c_parents]);
  }

  if($test_7 == "yes") {
    echo "TEST 7 ----------------------------------------------\n";
    echo "Inserting a new text document into 0x".dechex($collid)."\n";
    $objrec = "Type=Document\nDocumentType=text\nName=HWTest\nTitle=en:Component\nMimeType=text/plain\nAuthor=".$username;
    $contents = "Ein bischen Text";
    $doc =  hw_new_document($objrec, $contents, strlen($contents)+1);
    $objid = hw_insertdocument($connect, $collid, $doc);
    if(hw_error($connect)) {
      echo "ERROR: ".hw_errormsg($connect)."\n";
      exit;
    }
    $objrec = hw_getobject($connect, $objid);
    if(hw_error($connect)) {
      echo "ERROR: ".hw_errormsg($connect)."\n";
      exit;
    }
    $objarr = hw_objrec2array($objrec);
    list_attr($objarr);
  }

  if($test_8 == "yes") {
    echo "TEST 8 ----------------------------------------------\n";
    echo "Removing text document just inserted\n";
    $kk[0] = (int) $objid;
    hw_mv($connect, $kk, $collid, 0);
    if(hw_error($connect)) {
      echo "ERROR: ".hw_errormsg($connect)."\n";
      exit;
    }
    echo "If the document was really deleted you should see an error now\n";
    $objrec = hw_getobject($connect, $objid);
    if(hw_error($connect)) {
      echo "ERROR: ".hw_errormsg($connect)."\n";
    } else {
      $objarr = hw_objrec2array($objrec);
      list_attr($objarr);
    }
  }

  if($test_9 == "yes") {
    echo "TEST 9 ----------------------------------------------\n";
    echo "Searching for objects with $query\n";
    $objrecs = hw_getobjectbyqueryobj($connect, $query, -1);
    $c_objrecs = count($objrecs) - 1;
    echo "$c_objrecs found\n";
    for($i=0; $i<$c_objrecs; $i++) {
      $objarr = hw_objrec2array($objrecs[$i]);
      list_attr($objarr);
    }
    list_attr($objrecs[$c_objrecs]);
  }

  hw_close($connect);
?>