File: dtl_test_common.cpp

package info (click to toggle)
dtl 1.21-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 440 kB
  • sloc: cpp: 2,285; makefile: 2
file content (56 lines) | stat: -rw-r--r-- 1,721 bytes parent folder | download | duplicates (4)
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

#include "dtl_test_common.hpp"

string create_path (const string& test_name, string diff_name, enum type_diff t, bool is_use_suffix) {
    string ret;
    switch (t) {
    case TYPE_DIFF_SES:
        ret = (getcwd(NULL, 0) + string("/") + string("ses")   + string("/") + diff_name + string("/") + test_name);
        break;
    case TYPE_DIFF_UNI:
        ret = (getcwd(NULL, 0) + string("/") + string("hunks") + string("/") + diff_name + string("/") + test_name);
        break;
    }
    ret += is_use_suffix ? "_" : "";
    return ret;
}

size_t cal_diff_uni (const string& path_l, const string& path_r) {
    string   buf;
    ifstream lifs(path_l.c_str());
    ifstream rifs(path_r.c_str());

    vector< string > llines;
    vector< string > rlines;

    while (getline(lifs, buf)) {
        llines.push_back(buf);
    }
    
    while (getline(rifs, buf)) {
        rlines.push_back(buf);
    }

    Diff< string, vector< string > > diff_uni(llines, rlines);
    diff_uni.compose();
    return diff_uni.getEditDistance();
}

bool is_file_exist (string& fs) {
    FILE *fp;
    if ((fp = fopen(fs.c_str(), "r")) == NULL) {
        return false;
    }
    fclose(fp);
    return true;
}

void diff_resultset_exist_check (string &fs) {
    if (!is_file_exist(fs)) {
        cerr << "======================================================Error!!!======================================================" << endl;
        cerr << "diff result set:" << fs << " is not found." << endl;
        cerr << "======================================================Error!!!======================================================" << endl;
        cerr << "excute dtl_test in dtl/test!" << endl;
        exit(EXIT_FAILURE);
    }
}