OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [tools/] [src/] [libcdl/] [testsuite/] [libcdl/] [cdl5.cxx] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 26 unneback
//==========================================================================
2
//
3
//      cdl5.cxx
4
//
5
//      Basic test of the database class
6
//
7
//==========================================================================
8
//####COPYRIGHTBEGIN####
9
//                                                                          
10
// ----------------------------------------------------------------------------
11
// Copyright (C) 1999, 2000 Red Hat, Inc.
12
//
13
// This file is part of the eCos host tools.
14
//
15
// This program is free software; you can redistribute it and/or modify it 
16
// under the terms of the GNU General Public License as published by the Free 
17
// Software Foundation; either version 2 of the License, or (at your option) 
18
// any later version.
19
// 
20
// This program is distributed in the hope that it will be useful, but WITHOUT 
21
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
22
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
23
// more details.
24
// 
25
// You should have received a copy of the GNU General Public License along with
26
// this program; if not, write to the Free Software Foundation, Inc., 
27
// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
28
//
29
// ----------------------------------------------------------------------------
30
//                                                                          
31
//####COPYRIGHTEND####
32
//==========================================================================
33
//#####DESCRIPTIONBEGIN####                                             
34
//
35
// Author(s):           bartv
36
// Contributors:        bartv
37
// Date:                1999-01-22
38
// Description:         Test the database handling using the test data.
39
//
40
//####DESCRIPTIONEND####
41
//==========================================================================
42
 
43
#include <cstdio>
44
#include <cdlconfig.h>
45
#include <cdl.hxx>
46
#include <cyg/infra/testcase.h>
47
#include <cstdlib>
48
#include <algorithm>
49
 
50
#if 1
51
int
52
main(int argc, char** argv)
53
{
54
    // There should be one argument, the location of the component
55
    // repository. This is actually the data subdirectory in
56
    // libcdl/testsuite.
57
    if (2 != argc) {
58
        CYG_TEST_FAIL_FINISH("Missing command line argument to specify the component repository");
59
    }
60
 
61
    CdlDatabase database = 0;
62
    try {
63
        database = CdlDatabaseBody::make(argv[1]);
64
    }
65
    catch(std::bad_alloc e) {
66
        CYG_TEST_FAIL_FINISH("Out of memory when reading in the database");
67
    }
68
    catch(CdlInputOutputException e) {
69
        CYG_TEST_FAIL_FINISH(e.get_message().c_str());
70
    }
71
 
72
    bool ok = true;
73
    const std::vector<std::string>& packages = database->get_packages();
74
    if (2 > packages.size()) {
75
        CYG_TEST_FAIL("The database should have at least two packages");
76
        ok = false;
77
    }
78
    std::vector<std::string>::const_iterator srch = std::find(packages.begin(), packages.end(), "CYGPKG_PKG1");
79
    if (srch == packages.end()) {
80
        CYG_TEST_FAIL("There should be a package CYGPKG_PKG1");
81
        ok = false;
82
    }
83
    srch = std::find(packages.begin(), packages.end(), "CYGPKG_PKG2");
84
    if (srch == packages.end()) {
85
        CYG_TEST_FAIL("There should be a package CYGPKG_PKG2");
86
        ok = false;
87
    }
88
 
89
    const std::vector<std::string>& aliases     = database->get_package_aliases("CYGPKG_PKG1");
90
    const std::vector<std::string>& versions    = database->get_package_versions("CYGPKG_PKG1");
91
    const std::string& directory                = database->get_package_directory("CYGPKG_PKG1");
92
    if ("pkg1" != directory) {
93
        CYG_TEST_FAIL("Incorrect directory for CYGPKG_PKG1");
94
        ok = false;
95
    }
96
    if ((3 != aliases.size()) ||
97
        (aliases.end() == std::find(aliases.begin(), aliases.end(), "package1")) ||
98
        (aliases.end() == std::find(aliases.begin(), aliases.end(), "pkg1"))     ||
99
        (aliases.end() == std::find(aliases.begin(), aliases.end(), "another alias"))) {
100
        CYG_TEST_FAIL("Incorrect aliases for CYGPKG_PKG1");
101
        ok = false;
102
    }
103
    if ((2 != versions.size()) ||
104
        (versions.end() == std::find(versions.begin(), versions.end(), "current")) ||
105
        (versions.end() == std::find(versions.begin(), versions.end(), "v1.1"))) {
106
        CYG_TEST_FAIL("Versions of CYGPKG_PKG1 do not match expectations");
107
        ok = false;
108
    }
109
 
110
    if (ok) {
111
        CYG_TEST_PASS("Database ok");
112
    }
113
    return EXIT_SUCCESS;
114
}
115
 
116
#else
117
 
118
// Some more code to look at a packages database. This produces a simple
119
// dump.
120
 
121
int
122
main(int argc, char** argv)
123
{
124
    CdlDatabase database = 0;
125
    try {
126
        database = CdlDatabaseBody::make();
127
    }
128
    catch(std::bad_alloc e) {
129
        CYG_TEST_FAIL_FINISH("Out of memory reading in the database");
130
    }
131
    catch(CdlInputOutputException e) {
132
        CYG_TEST_FAIL_FINISH(e.get_message().c_str());
133
    }
134
 
135
    const std::vector<std::string>&             packages = database->get_packages();
136
    std::vector<std::string>::const_iterator    pkgs_i;
137
    std::vector<std::string>::const_iterator    data_i;
138
 
139
    printf("There are %d packages\n", packages.size());
140
    for (pkgs_i = packages.begin(); pkgs_i != packages.end(); pkgs_i++) {
141
        printf("Package %s\n", pkgs_i->c_str());
142
 
143
        const std::vector<std::string>& aliases         = database->get_package_aliases(*pkgs_i);
144
        const std::vector<std::string>& versions        = database->get_package_versions(*pkgs_i);
145
        const std::string&              directory       = database->get_package_directory(*pkgs_i);
146
 
147
        printf("  Directory : %s\n", directory.c_str());
148
        printf("  Aliases   :");
149
        for (data_i = aliases.begin(); data_i != aliases.end(); data_i++) {
150
            printf(" %s", data_i->c_str());
151
        }
152
        putchar('\n');
153
        printf("  Versions  :");
154
        for (data_i = versions.begin(); data_i != versions.end(); data_i++) {
155
            printf(" %s", data_i->c_str());
156
        }
157
        putchar('\n');
158
    }
159
 
160
    // stdout output is discarded if the test failures.
161
    CYG_TEST_FAIL("All data displayed.");
162
    return EXIT_FAILURE;
163
}
164
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.