summaryrefslogtreecommitdiff
path: root/tests/test_parser.cpp
blob: 363a0884d003c0d8f56224bd1d0bab9e5cfe2add (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
/*
 * test_parser.cpp
 *
 *  Created on: 16.09.2012
 *      Author: savop
 */

#include "../include/parser.h"
#include <iostream>

void checkSort(string s){

  upnp::cSortCriteria::SortCriteriaList list = upnp::cSortCriteria::parse(s);

  cout << "Sort:    \"" << s << "\"" << endl;
  for(upnp::cSortCriteria::SortCriteriaList::iterator it = list.begin(); it != list.end(); ++it){
    cout << "  " << (*it).property << " " <<((*it).sortDescending ? "DESC" : "ASC") << endl;
  }
  cout << endl;

}

void checkSearch(string t, string e) {

  string r = upnp::cSearch::parse(t);

  cout << "Suche:    \"" << t << "\"" << endl;
  cout << "Erwartet: \"" << e << "\"" << endl;
  cout << "Ergebnis: \"" << r << "\"" << endl;
  cout << "------->  " << (e.compare(r) ? "FEHLGESCHLAGEN!" : "ERFOLGREICH!") << endl << endl;

}

void checkFilter(string f){

  upnp::StringList list = upnp::cFilterCriteria::parse(f);

  cout << "Filter:  \"" << f << "\"" << endl;
  for(upnp::StringList::iterator it = list.begin(); it != list.end(); ++it){
    cout << "  " << (*it) << endl;
  }
  cout << endl;

}

int main(){
  checkSearch("upnp:class = \"object.item.imageItem\" and ( dc:date >= \"2001-10-01\" and dc:date <= \"2001-10-31\" )",
              "class == 'object.item.imageItem' AND ( date >= '2001-10-01' AND date <= '2001-10-31' ) ");

  checkSearch("@id = \"20\"",
              string());

  checkSearch("dc:title contains \"Christmas\"",
              "title LIKE '%Christmas%' ");

  checkSearch("upnp:class derivedfrom \"object.container.album\"",
              "class LIKE '%object.container.album%' ");

  checkFilter("@id,@parentID,@restricted,dc:title");

  checkFilter("*");

  checkFilter("@id,dc:title,upnp:longDescription,res");

  checkFilter("@id,@parentID,@restricted,dc:title,upnp:class,res,dc:date,@childCount,sec:CaptionInfo,sec:CaptionInfoEx,sec:dcmInfo,sec:MetaFileInfo,res@resolution,res@size,upnp:genre,dc:date,upnp:album,res@duration,upnp:albumArtURI,res@bitrate,dc:creator");

  checkSort("");

  checkSort("+dc:title,-dc:creator");

  checkSort("dc:title");

  checkSort("+upnp:class");

  checkSort("+@id");

  return 0;
}