e7d8985e2623bc7d7255453a5bc9fe5b2e6392fb
[platform/upstream/libzypp.git] / tests / zypp / Target_test.cc
1 #include <iostream>
2 #include <fstream>
3 #include <list>
4 #include <string>
5
6 // Boost.Test
7 #include <boost/test/auto_unit_test.hpp>
8
9 #include "zypp/base/Logger.h"
10 #include "zypp/base/Exception.h"
11 #include "zypp/ZYppFactory.h"
12 #include "zypp/ZYpp.h"
13 #include "zypp/ZYppFactory.h"
14 #include "zypp/TmpPath.h"
15
16 using boost::unit_test::test_case;
17 using namespace std;
18 using namespace zypp;
19 using namespace zypp::filesystem;
20
21 BOOST_AUTO_TEST_CASE(target_test)
22 {
23
24     filesystem::TmpDir tmp;
25
26     ZYpp::Ptr z = getZYpp();
27
28     // create the products.d directory
29     assert_dir(tmp.path() / "/etc/products.d" );
30     BOOST_CHECK( copy( Pathname(TESTS_SRC_DIR) / "/zypp/data/Target/product.prod",  tmp.path() / "/etc/products.d/product.prod") == 0 );
31
32     // make it the base product
33     BOOST_CHECK( symlink(tmp.path() / "/etc/products.d/product.prod", tmp.path() / "/etc/products.d/baseproduct" ) == 0 );
34
35     z->initializeTarget( tmp.path() );
36
37     // bsc#1024741: Omit creating a new uid for chrooted systems (if it already has one, fine)
38     BOOST_CHECK( ! PathInfo( tmp.path() / "/var/lib/zypp/AnonymousUniqueId").isExist() );
39     // create an artificial one
40     {
41       Pathname f( tmp.path() / "/var/lib/zypp" );
42       filesystem::assert_dir( f );
43       std::ofstream o( (f/"AnonymousUniqueId").c_str() );
44       o << "AnonymousUniqueId";
45     }
46     BOOST_CHECK( PathInfo( tmp.path() / "/var/lib/zypp/AnonymousUniqueId").isExist() );
47     BOOST_CHECK_EQUAL( z->target()->anonymousUniqueId(), "AnonymousUniqueId" );
48
49     // now check the base product
50     BOOST_CHECK_EQUAL( z->target()->targetDistribution(), "sle-10-i586");
51     BOOST_CHECK_EQUAL( z->target()->targetDistributionRelease(), "special_edition");
52     BOOST_CHECK_EQUAL( z->target()->distributionVersion(), "10");
53
54     Target::DistributionLabel dlabel( z->target()->distributionLabel() );
55     BOOST_CHECK_EQUAL( dlabel.summary, "A cool distribution" );
56     BOOST_CHECK_EQUAL( dlabel.shortName, "" );
57 }