~ubuntu-branches/ubuntu/oneiric/strigi/oneiric

« back to all changes in this revision

Viewing changes to tests/streamanalyzer/xesam/xesam2strigitest.cpp

  • Committer: Package Import Robot
  • Author(s): Felix Geyer
  • Date: 2011-09-24 17:12:15 UTC
  • mfrom: (1.2.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: package-import@ubuntu.com-20110924171215-zmbi1f77jntvz65h
Tags: upstream-0.7.6
ImportĀ upstreamĀ versionĀ 0.7.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of Strigi Desktop Search
2
 
 *
3
 
 * Copyright (C) 2007 Flavio Castelli <flavio.castelli@gmail.com>
4
 
 *
5
 
 * This library is free software; you can redistribute it and/or
6
 
 * modify it under the terms of the GNU Library General Public
7
 
 * License as published by the Free Software Foundation; either
8
 
 * version 2 of the License, or (at your option) any later version.
9
 
 *
10
 
 * This library is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 
 * Library General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU Library General Public License
16
 
 * along with this library; see the file COPYING.LIB.  If not, write to
17
 
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
 
 * Boston, MA 02110-1301, USA.
19
 
 */
20
 
 
21
 
#include "xesam2strigitest.h"
22
 
#include "xesam2strigi.h"
23
 
 
24
 
#include <cstdlib>
25
 
#include <cstring>
26
 
#include <errno.h>
27
 
#include <fstream>
28
 
#include <unistd.h>
29
 
#include <stdlib.h>
30
 
 
31
 
using namespace std;
32
 
using namespace strigiunittest;
33
 
 
34
 
// Registers the fixture into the 'registry'
35
 
CPPUNIT_TEST_SUITE_REGISTRATION( Xesam2StrigiTest );
36
 
 
37
 
void Xesam2StrigiTest::setUp() {
38
 
  //africa.txt
39
 
  m_ulQueries.insert ("type:image size>=1mb tag:flower africa");
40
 
  //africa2.txt
41
 
  m_ulQueries.insert ("type:image size>=1mb tag:flower south africa");
42
 
  //africa2.txt
43
 
  m_ulQueries.insert ("type:image size>=1mb tag:flower south africa");
44
 
  //helloworld.txt
45
 
  m_ulQueries.insert ("\"hello world, how are you?\"cle");
46
 
  //helloworld2.txt
47
 
  m_ulQueries.insert ("\"hello world, how are you?\"CL fine thanks");
48
 
  //helloworld3.txt
49
 
  m_ulQueries.insert ("+ \"hello world, how are you?\"cS and fine thanks");
50
 
  //hendrix.txt
51
 
  m_ulQueries.insert ("type:music hendrix");
52
 
  //hendrix2.txt
53
 
  m_ulQueries.insert ("type:music creator=\"James Marshall Hendrix\"");
54
 
  //negate.txt
55
 
  m_ulQueries.insert ("-type:music hendrix");
56
 
 
57
 
  xesam2strigi = new Xesam2Strigi();
58
 
}
59
 
 
60
 
void Xesam2StrigiTest::tearDown()
61
 
{
62
 
  if (xesam2strigi)
63
 
    delete xesam2strigi;
64
 
  xesam2strigi = NULL;
65
 
}
66
 
 
67
 
void Xesam2StrigiTest::parseUlFromString()
68
 
{
69
 
  for (set<string>::iterator iter = m_ulQueries.begin();
70
 
       iter != m_ulQueries.end(); iter++)
71
 
  {
72
 
    if (!xesam2strigi->parse (*iter, Xesam2Strigi::UserLanguage)) {
73
 
      string msg = "Failed to parse xesam userlanguage query: |";
74
 
      msg += *iter;
75
 
      msg += "| from string";
76
 
      CPPUNIT_FAIL (msg);
77
 
    }
78
 
  }
79
 
}
80
 
 
81
 
void Xesam2StrigiTest::parseUlFromFile()
82
 
{
83
 
// create a temporary file
84
 
  char filename[13];
85
 
  ofstream out;
86
 
 
87
 
    // generate index dir name
88
 
  strcpy(filename, "strigiXXXXXX");
89
 
 
90
 
  if (mkstemp(filename) == -1) {
91
 
    printf ("Error creating temporary file because of: ");
92
 
    printf ("%s\n", strerror (errno));
93
 
    return;
94
 
  }
95
 
  else
96
 
    printf ("created temporary file: %s\n", filename);
97
 
 
98
 
  for (set<string>::iterator iter = m_ulQueries.begin();
99
 
       iter != m_ulQueries.end(); iter++)
100
 
  {
101
 
    out.open(filename);
102
 
    out << *iter;
103
 
    out.close();
104
 
    
105
 
    if (!xesam2strigi->parse_file (filename, Xesam2Strigi::UserLanguage)) {
106
 
      string msg = "Failed to parse xesam userlanguage query: |";
107
 
      msg += *iter;
108
 
      msg += "| from file";
109
 
      CPPUNIT_FAIL (msg);
110
 
    }
111
 
  }
112
 
 
113
 
    if (unlink(filename) == -1) {
114
 
        fprintf(stderr, "unable to delete temporary file %s because of: ",
115
 
            filename);
116
 
        printf ("%s\n", strerror (errno));
117
 
    }
118
 
}
119