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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [libcdl/] [testsuite/] [libcdl/] [cdl5.cxx] - Blame information for rev 790

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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