diff --git a/src/image/test/ImagePoolTest.cc b/src/image/test/ImagePoolTest.cc new file mode 100644 index 0000000000..8882c1e7ae --- /dev/null +++ b/src/image/test/ImagePoolTest.cc @@ -0,0 +1,152 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) */ +/* */ +/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ +/* not use this file except in compliance with the License. You may obtain */ +/* a copy of the License at */ +/* */ +/* http://www.apache.org/licenses/LICENSE-2.0 */ +/* */ +/* Unless required by applicable law or agreed to in writing, software */ +/* distributed under the License is distributed on an "AS IS" BASIS, */ +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ +/* See the License for the specific language governing permissions and */ +/* limitations under the License. */ +/* -------------------------------------------------------------------------- */ + +#include +#include +#include + +#include "ImagePool.h" +#include "PoolTest.h" + +using namespace std; + +const int uids[] = {123, 261, 123}; + +const string names[] = {"VM one", "Second VM", "VM one"}; + + // TODO change templates +const string templates[] = +{ + "NAME = \"VM one\"\n" + "MEMORY = 128\n" + "CPU = 1", + + "NAME = \"Second VM\"\n" + "MEMORY = 256\n" + "CPU = 2", + + "NAME = \"VM one\"\n" + "MEMORY = 1024\n" + "CPU = 1" +}; + + // TODO change xmls +const string xmls[] = +{ + "0123VM one010000000000000000", + + "1261Second VM0" + "1000000000000<" + "/ETIME>0000", + + "0123VM one010000000000000000" +}; + +/* +// This xml dump result has the STIMEs modified to 0000000000 +const string xml_dump = + "01A userVM one" + "01000000000000000012B userSecond VM0200000000000" + "00000"; + +const string xml_dump_where = + "01A userVM one" + "010000000000000000"; + + +//*/ + +/* ************************************************************************* */ +/* ************************************************************************* */ + +class ImagePoolTest : public PoolTest +{ + CPPUNIT_TEST_SUITE (ImagePoolTest); + + ALL_POOLTEST_CPPUNIT_TESTS(); + + CPPUNIT_TEST_SUITE_END (); + +protected: + + void bootstrap(SqlDB* db) + { + ImagePool::bootstrap(db); + }; + + PoolSQL* create_pool(SqlDB* db) + { + return new ImagePool(db, "source_prefix", "OS", "IDE"); + }; + + int allocate(int index) + { + int oid; + return ((ImagePool*)pool)->allocate(uids[index], + templates[index], + false); + }; + + void check(int index, PoolObjectSQL* obj) + { + CPPUNIT_ASSERT( obj != 0 ); + + string xml_str = ""; + + // Get the xml and replace the STIME to 0, so we can compare it + ((Image*)obj)->to_xml(xml_str); + + CPPUNIT_ASSERT( ((Image*)obj)->get_name() == names[index] ); + CPPUNIT_ASSERT( xml_str == xmls[index]); + }; + +public: + ImagePoolTest(){}; + + ~ImagePoolTest(){}; + + + /* ********************************************************************* */ + /* ********************************************************************* */ + +}; + +/* ************************************************************************* */ +/* ************************************************************************* */ + +int main(int argc, char ** argv) +{ + return PoolTest::main(argc, argv, ImagePoolTest::suite()); +} diff --git a/src/image/test/SConstruct b/src/image/test/SConstruct new file mode 100644 index 0000000000..bf11121dbb --- /dev/null +++ b/src/image/test/SConstruct @@ -0,0 +1,102 @@ +# -------------------------------------------------------------------------- +# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# -------------------------------------------------------------------------- + +import os +import sys +import shutil +sys.path.append("../../../share/scons") +from lex_bison import * + +# This is the absolute path where the project is located +cwd="../../../" + +# Environment that will be applied to each scons child +main_env=Environment() +main_env['ENV']['PATH']=os.environ['PATH'] + +# Add builders for flex and bison +add_lex(main_env) +add_bison(main_env) + +# Include dirs +main_env.Append(CPPPATH=[ + cwd + '/include', + cwd + '/include/test', + '/usr/include/cppunit/', +]) + +# Library dirs +main_env.Append(LIBPATH=[ + cwd + '/src/common', + cwd + '/src/log', + cwd + '/src/nebula', + cwd + '/src/sql', + cwd + '/src/pool', + cwd + '/src/template', + cwd + '/src/vm', + cwd + '/src/hm', + cwd + '/src/mad', + cwd + '/src/vnm', + cwd + '/src/um', + cwd + '/src/image', + '/usr/include/openssl/', +]) + +main_env.Append(LIBS=[ + 'nebula_image', + 'nebula_um', + 'nebula_vm', + 'nebula_mad', + 'nebula_hm', + 'nebula_vnm', + 'nebula_template', + 'nebula_pool', + 'nebula_common', + 'nebula_log', + 'nebula_core', + 'nebula_sql', + 'cppunit', + 'dl', + 'pthread', + 'crypto', +]) + +# MYSQL +main_env.Append(LIBPATH=["/usr/lib/mysql"]) +main_env.Append(CPPPATH=["/usr/include/mysql"]) + +sqlite=ARGUMENTS.get('sqlite', 'yes') +if sqlite=='yes': + main_env.Append(CPPFLAGS=["-DSQLITE_DB"]) + main_env.Append(LIBS=[ 'sqlite3', ]) + +# MySQL +mysql=ARGUMENTS.get('mysql', 'no') +if mysql=='yes': + main_env.Append(CPPFLAGS=["-DMYSQL_DB"]) + main_env.Append(LIBS=[ 'mysqlclient', ]) + +# Compile flags +main_env.Append(CPPFLAGS=[ + "-g", + "-Wall" +]) + +# Linking flags +main_env.Append(LDFLAGS=["-g "]) + +main_env.Program('test','ImagePoolTest.cc') +