File: import3.cc

package info (click to toggle)
yapet 0.6-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 6,012 kB
  • ctags: 2,913
  • sloc: ansic: 13,661; cpp: 11,384; sh: 4,814; makefile: 847; yacc: 291; sed: 16
file content (60 lines) | stat: -rw-r--r-- 1,338 bytes parent folder | download | duplicates (2)
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
// $Id: import3.cc 2845 2009-09-01 09:33:31Z rafi $
// Tests the error detection.
// Relies on test2.csv

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#ifdef HAVE_IOSTREAM
# include <iostream>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <typeinfo>

#include <csvimport.h>
#include "testpaths.h"

int main (int, char**) {
#ifndef TESTS_VERBOSE
    int stdout_redir_fd = open("/dev/null", O_WRONLY | O_APPEND);
    dup2(stdout_redir_fd,STDOUT_FILENO);
#endif
    std::cout << std::endl;

    try {
        std::cout << " ==> Importing from test2.csv" << std::endl;
        std::cout << " ==> Testing for error recognition" << std::endl;
	CSVImport imp (SRCDIR "/test2.csv", "test2.pet", ',', true);

        imp.import ("test2");
        imp.printLog();

        if (imp.numErrors() != 2)
            return 1;

        std::list<CSVImport::LogEntry> logs (imp.getLog() );

        if (logs.size() != 2)
            return 1;

        std::list<CSVImport::LogEntry>::const_iterator it = logs.begin();

        if ( (*it).lineno != 2)
            return 1;

        it++;

        if ( (*it).lineno != 10)
            return 1;
    } catch (std::exception& ex) {
        std::cout << typeid (ex).name() << ": " << ex.what() << std::endl;
        return 1;
    }

    return 0;

}