1 //==========================================================================
5 // Basic test of the database class
7 //==========================================================================
8 //####COPYRIGHTBEGIN####
10 // ----------------------------------------------------------------------------
11 // Copyright (C) 1999, 2000 Red Hat, Inc.
13 // This file is part of the eCos host tools.
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)
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
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.
29 // ----------------------------------------------------------------------------
31 //####COPYRIGHTEND####
32 //==========================================================================
33 //#####DESCRIPTIONBEGIN####
36 // Contributors: bartv
38 // Description: Test the database handling using the test data.
40 //####DESCRIPTIONEND####
41 //==========================================================================
44 #include <cdlconfig.h>
46 #include <cyg/infra/testcase.h>
52 main(int argc, char** argv)
54 // There should be one argument, the location of the component
55 // repository. This is actually the data subdirectory in
58 CYG_TEST_FAIL_FINISH("Missing command line argument to specify the component repository");
61 CdlDatabase database = 0;
63 database = CdlDatabaseBody::make(argv[1]);
65 catch(std::bad_alloc e) {
66 CYG_TEST_FAIL_FINISH("Out of memory when reading in the database");
68 catch(CdlInputOutputException e) {
69 CYG_TEST_FAIL_FINISH(e.get_message().c_str());
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");
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");
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");
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");
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");
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");
111 CYG_TEST_PASS("Database ok");
118 // Some more code to look at a packages database. This produces a simple
122 main(int argc, char** argv)
124 CdlDatabase database = 0;
126 database = CdlDatabaseBody::make();
128 catch(std::bad_alloc e) {
129 CYG_TEST_FAIL_FINISH("Out of memory reading in the database");
131 catch(CdlInputOutputException e) {
132 CYG_TEST_FAIL_FINISH(e.get_message().c_str());
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;
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());
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);
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());
153 printf(" Versions :");
154 for (data_i = versions.begin(); data_i != versions.end(); data_i++) {
155 printf(" %s", data_i->c_str());
160 // stdout output is discarded if the test failures.
161 CYG_TEST_FAIL("All data displayed.");