[buildd-tools-devel] [PATCH 3/3] Unify chroot type, keyfile and detail handling

Jan-Marek Glogowski glogow at fbihome.de
Sun Mar 29 19:38:02 UTC 2009


Type, detail name and keyfile key name data are combined in the
get_chroot_strings function to generalize the container
management, but keep individual keyfile key names.
---
 sbuild/sbuild-chroot-block-device.cc |   33 +++++++------------
 sbuild/sbuild-chroot-block-device.h  |    6 ++-
 sbuild/sbuild-chroot-directory.cc    |   40 +++++-----------------
 sbuild/sbuild-chroot-directory.h     |   17 ++-------
 sbuild/sbuild-chroot-file.cc         |   33 ++++++++----------
 sbuild/sbuild-chroot-file.h          |    6 ++-
 sbuild/sbuild-chroot-loopback.cc     |   34 +++++++------------
 sbuild/sbuild-chroot-loopback.h      |    6 ++-
 sbuild/sbuild-chroot-lvm-snapshot.cc |   22 ++++++++----
 sbuild/sbuild-chroot-lvm-snapshot.h  |    6 ++-
 sbuild/sbuild-chroot-plain.cc        |   16 ++++++---
 sbuild/sbuild-chroot-plain.h         |    6 ++-
 sbuild/sbuild-chroot.cc              |   61 ++++++++++++++++++++++++++++++---
 sbuild/sbuild-chroot.h               |   12 ++++--
 test/sbuild-chroot-block-device.cc   |   13 +++++--
 test/sbuild-chroot-directory.cc      |   12 +++++--
 test/sbuild-chroot-file.cc           |   11 ++++--
 test/sbuild-chroot-lvm-snapshot.cc   |   11 ++++--
 test/sbuild-chroot-plain.cc          |   11 ++++--
 test/sbuild-chroot.cc                |   28 ++++++++++++----
 20 files changed, 224 insertions(+), 160 deletions(-)

diff --git a/sbuild/sbuild-chroot-block-device.cc b/sbuild/sbuild-chroot-block-device.cc
index ebc6fb4..e704a09 100644
--- a/sbuild/sbuild-chroot-block-device.cc
+++ b/sbuild/sbuild-chroot-block-device.cc
@@ -56,21 +56,11 @@ chroot_block_device::set_container (std::string const& device)
   chroot::set_container(device);
 }
 
-std::string const&
-chroot_block_device::get_chroot_type () const
-{
-  static const std::string type("block-device");
-
-  return type;
-}
-
 void
 chroot_block_device::setup_env (environment& env)
 {
   chroot::setup_env(env);
   chroot_mountable::setup_env(env);
-
-  env.add("CHROOT_DEVICE", get_container());
 }
 
 void
@@ -144,9 +134,6 @@ chroot_block_device::get_details (format_detail& detail) const
 {
   this->chroot::get_details(detail);
   this->chroot_mountable::get_details(detail);
-
-  if (!this->get_container().empty())
-    detail.add(_("Device"), get_container());
 }
 
 void
@@ -154,10 +141,6 @@ chroot_block_device::get_keyfile (keyfile& keyfile) const
 {
   chroot::get_keyfile(keyfile);
   chroot_mountable::get_keyfile(keyfile);
-
-  keyfile::set_object_value(*(static_cast<const chroot *>(this)),
-			    &chroot_block_device::get_container,
-			    keyfile, get_name(), "device");
 }
 
 void
@@ -166,10 +149,18 @@ chroot_block_device::set_keyfile (keyfile const& keyfile,
 {
   chroot::set_keyfile(keyfile, used_keys);
   chroot_mountable::set_keyfile(keyfile, used_keys);
+}
 
-  keyfile::get_object_value(*this, &chroot_block_device::set_container,
-			    keyfile, get_name(), "device",
-			    keyfile::PRIORITY_REQUIRED);
-  used_keys.push_back("device");
+void
+chroot_block_device::get_chroot_strings (std::string *type,
+					 std::string *key_name,
+					 std::string *detail_name) const
+{
+  if (type != NULL)
+    *type = "block-device";
+  if (key_name != NULL)
+    *key_name = "device";
+  if (detail_name != NULL)
+    *detail_name = "Device";
 }
 
diff --git a/sbuild/sbuild-chroot-block-device.h b/sbuild/sbuild-chroot-block-device.h
index 2e86914..9b53ec9 100644
--- a/sbuild/sbuild-chroot-block-device.h
+++ b/sbuild/sbuild-chroot-block-device.h
@@ -58,8 +58,10 @@ namespace sbuild
     void
     set_container (std::string const& device);
 
-    std::string const&
-    get_chroot_type () const;
+    virtual void
+    get_chroot_strings (std::string *type,
+			std::string *key_name,
+			std::string *detail_name) const;
 
     virtual void
     setup_env (environment& env);
diff --git a/sbuild/sbuild-chroot-directory.cc b/sbuild/sbuild-chroot-directory.cc
index e08e772..237b616 100644
--- a/sbuild/sbuild-chroot-directory.cc
+++ b/sbuild/sbuild-chroot-directory.cc
@@ -57,14 +57,6 @@ chroot_directory::get_path () const
     return get_container();
 }
 
-std::string const&
-chroot_directory::get_chroot_type () const
-{
-  static const std::string type("directory");
-
-  return type;
-}
-
 void
 chroot_directory::setup_lock (chroot::setup_type type,
 			      bool               lock,
@@ -93,12 +85,6 @@ chroot_directory::get_session_flags () const
 }
 
 void
-chroot_directory::get_details (format_detail& detail) const
-{
-  chroot::get_details(detail);
-}
-
-void
 chroot_directory::set_container (std::string const& directory)
 {
   if (!directory.empty() && !is_absname(directory))
@@ -109,23 +95,15 @@ chroot_directory::set_container (std::string const& directory)
 }
 
 void
-chroot_directory::get_keyfile (keyfile& keyfile) const
+chroot_directory::get_chroot_strings (std::string *type,
+				      std::string *key_name,
+				      std::string *detail_name) const
 {
-  chroot::get_keyfile(keyfile);
-
-  keyfile::set_object_value(*(static_cast<const chroot *>(this)),
-			    &chroot_directory::get_container,
-			    keyfile, get_name(), "location");
+  if (type != NULL)
+    *type = "directory";
+  if (key_name != NULL)
+    *key_name = "location";
+  if (detail_name != NULL)
+    *detail_name = "Location";
 }
 
-void
-chroot_directory::set_keyfile (keyfile const& keyfile,
-			       string_list&   used_keys)
-{
-  chroot::set_keyfile(keyfile, used_keys);
-
-  keyfile::get_object_value(*this, &chroot_directory::set_container,
-			    keyfile, get_name(), "location",
-			    keyfile::PRIORITY_REQUIRED);
-  used_keys.push_back("location");
-}
diff --git a/sbuild/sbuild-chroot-directory.h b/sbuild/sbuild-chroot-directory.h
index 69e25ec..3dedc55 100644
--- a/sbuild/sbuild-chroot-directory.h
+++ b/sbuild/sbuild-chroot-directory.h
@@ -53,8 +53,10 @@ namespace sbuild
     virtual std::string
     get_path () const;
 
-    virtual std::string const&
-    get_chroot_type () const;
+    virtual void
+    get_chroot_strings (std::string *type,
+			std::string *key_name,
+			std::string *detail_name) const;
 
     virtual session_flags
     get_session_flags () const;
@@ -64,17 +66,6 @@ namespace sbuild
     setup_lock (chroot::setup_type type,
 		bool               lock,
 		int                status);
-
-    virtual void
-    get_details (format_detail& detail) const;
-
-    virtual void
-    get_keyfile (keyfile& keyfile) const;
-
-    virtual void
-    set_keyfile (keyfile const& keyfile,
-		 string_list&   used_keys);
-
   };
 
 }
diff --git a/sbuild/sbuild-chroot-file.cc b/sbuild/sbuild-chroot-file.cc
index d02b59b..17bd546 100644
--- a/sbuild/sbuild-chroot-file.cc
+++ b/sbuild/sbuild-chroot-file.cc
@@ -82,21 +82,12 @@ chroot_file::set_file_repack (bool repack)
   this->repack = repack;
 }
 
-std::string const&
-chroot_file::get_chroot_type () const
-{
-  static const std::string type("file");
-
-  return type;
-}
-
 void
 chroot_file::setup_env (environment& env)
 {
   chroot::setup_env(env);
   chroot_source::setup_env(env);
 
-  env.add("CHROOT_FILE", get_container());
   env.add("CHROOT_FILE_REPACK", this->repack);
 }
 
@@ -144,7 +135,6 @@ chroot_file::get_details (format_detail& detail) const
 
   if (!get_container().empty())
     detail
-      .add(_("File"), get_container())
       .add(_("File Repack"), this->repack);
 }
 
@@ -154,10 +144,6 @@ chroot_file::get_keyfile (keyfile& keyfile) const
   chroot::get_keyfile(keyfile);
   chroot_source::get_keyfile(keyfile);
 
-  keyfile::set_object_value(*(static_cast<const chroot *>(this)),
-			    &chroot_file::get_container,
-			    keyfile, get_name(), "file");
-
   if (get_active())
     keyfile::set_object_value(*this, &chroot_file::get_file_repack,
 			      keyfile, get_name(), "file-repack");
@@ -170,11 +156,6 @@ chroot_file::set_keyfile (keyfile const& keyfile,
   chroot::set_keyfile(keyfile, used_keys);
   chroot_source::set_keyfile(keyfile, used_keys);
 
-  keyfile::get_object_value(*this, &chroot_file::set_container,
-			    keyfile, get_name(), "file",
-			    keyfile::PRIORITY_REQUIRED);
-  used_keys.push_back("file");
-
   keyfile::get_object_value(*this, &chroot_file::set_file_repack,
 			    keyfile, get_name(), "file-repack",
 			    get_active() ?
@@ -182,3 +163,17 @@ chroot_file::set_keyfile (keyfile const& keyfile,
 			    keyfile::PRIORITY_DISALLOWED);
   used_keys.push_back("file-repack");
 }
+
+void
+chroot_file::get_chroot_strings (std::string *type,
+				 std::string *key_name,
+				 std::string *detail_name) const
+{
+  if (type != NULL)
+    *type = "file";
+  if (key_name != NULL)
+    *key_name = "file";
+  if (detail_name != NULL)
+    *detail_name = "File";
+}
+
diff --git a/sbuild/sbuild-chroot-file.h b/sbuild/sbuild-chroot-file.h
index fbf11f7..24710d4 100644
--- a/sbuild/sbuild-chroot-file.h
+++ b/sbuild/sbuild-chroot-file.h
@@ -75,8 +75,10 @@ namespace sbuild
     void
     set_file_repack (bool repack);
 
-    virtual std::string const&
-    get_chroot_type () const;
+    virtual void
+    get_chroot_strings (std::string *type,
+			std::string *key_name,
+			std::string *detail_name) const;
 
     virtual void
     setup_env (environment& env);
diff --git a/sbuild/sbuild-chroot-loopback.cc b/sbuild/sbuild-chroot-loopback.cc
index ec1f41d..35fc044 100644
--- a/sbuild/sbuild-chroot-loopback.cc
+++ b/sbuild/sbuild-chroot-loopback.cc
@@ -56,21 +56,11 @@ chroot_loopback::set_container (std::string const& file)
   chroot_mountable::set_container(file);
 }
 
-std::string const&
-chroot_loopback::get_chroot_type () const
-{
-  static const std::string type("loopback");
-
-  return type;
-}
-
 void
 chroot_loopback::setup_env (environment& env)
 {
   chroot::setup_env(env);
   chroot_mountable::setup_env(env);
-
-  env.add("CHROOT_FILE", get_container());
 }
 
 void
@@ -107,9 +97,6 @@ chroot_loopback::get_details (format_detail& detail) const
 {
   this->chroot::get_details(detail);
   this->chroot_mountable::get_details(detail);
-
-  if (!this->get_container().empty())
-    detail.add(_("File"), get_container());
 }
 
 void
@@ -117,10 +104,6 @@ chroot_loopback::get_keyfile (keyfile& keyfile) const
 {
   chroot::get_keyfile(keyfile);
   chroot_mountable::get_keyfile(keyfile);
-
-  keyfile::set_object_value(*(static_cast<const chroot *>(this)),
-			    &chroot_loopback::get_container,
-			    keyfile, get_name(), "file");
 }
 
 void
@@ -129,9 +112,18 @@ chroot_loopback::set_keyfile (keyfile const& keyfile,
 {
   chroot::set_keyfile(keyfile, used_keys);
   chroot_mountable::set_keyfile(keyfile, used_keys);
+}
 
-  keyfile::get_object_value(*this, &chroot_loopback::set_container,
-			    keyfile, get_name(), "file",
-			    keyfile::PRIORITY_REQUIRED);
-  used_keys.push_back("file");
+void
+chroot_loopback::get_chroot_strings (std::string *type,
+				     std::string *key_name,
+				     std::string *detail_name) const
+{
+  if (type != NULL)
+    *type = "loopback";
+  if (key_name != NULL)
+    *key_name = "file";
+  if (detail_name != NULL)
+    *detail_name = "File";
 }
+
diff --git a/sbuild/sbuild-chroot-loopback.h b/sbuild/sbuild-chroot-loopback.h
index 9749fd8..91ed269 100644
--- a/sbuild/sbuild-chroot-loopback.h
+++ b/sbuild/sbuild-chroot-loopback.h
@@ -54,8 +54,10 @@ namespace sbuild
     virtual void
     set_container (std::string const& file);
 
-    std::string const&
-    get_chroot_type () const;
+    virtual void
+    get_chroot_strings (std::string *type,
+			std::string *key_name,
+			std::string *detail_name) const;
 
     virtual void
     setup_env (environment& env);
diff --git a/sbuild/sbuild-chroot-lvm-snapshot.cc b/sbuild/sbuild-chroot-lvm-snapshot.cc
index 1b5f2d7..4423b62 100644
--- a/sbuild/sbuild-chroot-lvm-snapshot.cc
+++ b/sbuild/sbuild-chroot-lvm-snapshot.cc
@@ -88,14 +88,6 @@ chroot_lvm_snapshot::set_snapshot_options (std::string const& snapshot_options)
   this->snapshot_options = snapshot_options;
 }
 
-std::string const&
-chroot_lvm_snapshot::get_chroot_type () const
-{
-  static const std::string type("lvm-snapshot");
-
-  return type;
-}
-
 void
 chroot_lvm_snapshot::setup_env (environment& env)
 {
@@ -236,3 +228,17 @@ chroot_lvm_snapshot::set_keyfile (keyfile const& keyfile,
 			    keyfile::PRIORITY_REQUIRED);
   used_keys.push_back("lvm-snapshot-options");
 }
+
+void
+chroot_lvm_snapshot::get_chroot_strings (std::string *type,
+					 std::string *key_name,
+					 std::string *detail_name) const
+{
+  if (type != NULL)
+    *type = "lvm-snapshot";
+  if (key_name != NULL)
+    *key_name = "device";
+  if (detail_name != NULL)
+    *detail_name = "LVM Snapshot Device";
+}
+
diff --git a/sbuild/sbuild-chroot-lvm-snapshot.h b/sbuild/sbuild-chroot-lvm-snapshot.h
index 1e9984a..fe6048a 100644
--- a/sbuild/sbuild-chroot-lvm-snapshot.h
+++ b/sbuild/sbuild-chroot-lvm-snapshot.h
@@ -85,8 +85,10 @@ namespace sbuild
     void
     set_snapshot_options (std::string const& snapshot_options);
 
-    virtual std::string const&
-    get_chroot_type () const;
+    virtual void
+    get_chroot_strings (std::string *type,
+			std::string *key_name,
+			std::string *detail_name) const;
 
     virtual void
     setup_env (environment& env);
diff --git a/sbuild/sbuild-chroot-plain.cc b/sbuild/sbuild-chroot-plain.cc
index 46b0157..437c67e 100644
--- a/sbuild/sbuild-chroot-plain.cc
+++ b/sbuild/sbuild-chroot-plain.cc
@@ -46,10 +46,16 @@ chroot_plain::clone () const
   return ptr(new chroot_plain(*this));
 }
 
-std::string const&
-chroot_plain::get_chroot_type () const
+void
+chroot_plain::get_chroot_strings (std::string *type,
+				  std::string *key_name,
+				  std::string *detail_name) const
 {
-  static const std::string type("plain");
-
-  return type;
+  if (type != NULL)
+    *type = "plain";
+  if (key_name != NULL)
+    *key_name = "location";
+  if (detail_name != NULL)
+    *detail_name = "Location";
 }
+
diff --git a/sbuild/sbuild-chroot-plain.h b/sbuild/sbuild-chroot-plain.h
index adcbd22..51115d8 100644
--- a/sbuild/sbuild-chroot-plain.h
+++ b/sbuild/sbuild-chroot-plain.h
@@ -42,8 +42,10 @@ namespace sbuild
     virtual chroot::ptr
     clone () const;
 
-    virtual std::string const&
-    get_chroot_type () const;
+    virtual void
+    get_chroot_strings (std::string *type,
+			std::string *key_name,
+			std::string *detail_name) const;
   };
 
 }
diff --git a/sbuild/sbuild-chroot.cc b/sbuild/sbuild-chroot.cc
index aec634e..41a314c 100644
--- a/sbuild/sbuild-chroot.cc
+++ b/sbuild/sbuild-chroot.cc
@@ -386,9 +386,28 @@ sbuild::chroot::set_persona (personality const& persona)
 void
 sbuild::chroot::setup_env (environment& env)
 {
-  env.add("CHROOT_TYPE", get_chroot_type());
+  std::string type, key_name;
+  get_chroot_strings(&type, &key_name, NULL);
+
+  env.add("CHROOT_TYPE", type);
   env.add("CHROOT_NAME", get_name());
   env.add("CHROOT_DESCRIPTION", get_description());
+
+  if (!key_name.empty())
+    {
+      for (std::string::iterator pos = key_name.begin();
+		pos != key_name.end(); ++pos)
+	{
+	  if (*pos == '-')
+	    *pos = '_';
+	  else
+	    *pos = toupper(*pos);
+	}
+
+      key_name.insert(0, "CHROOT_");
+      env.add(key_name, get_container());
+    }
+
   env.add("CHROOT_CONTAINER", get_container());
   env.add("CHROOT_LOCATION", get_location());
   env.add("CHROOT_MOUNT_LOCATION", get_mount_location());
@@ -467,17 +486,30 @@ sbuild::chroot::unlock (setup_type type,
 void
 sbuild::chroot::get_details (format_detail& detail) const
 {
+  std::string type, detail_name;
+  get_chroot_strings(&type, NULL, &detail_name);
+
   detail
     .add(_("Name"), get_name())
     .add(_("Description"), get_description())
-    .add(_("Type"), get_chroot_type())
+    .add(_("Type"), type)
     .add(_("Priority"), get_priority())
     .add(_("Users"), get_users())
     .add(_("Groups"), get_groups())
     .add(_("Root Users"), get_root_users())
     .add(_("Root Groups"), get_root_groups())
-    .add(_("Aliases"), get_aliases())
-    .add(_("Container"), get_container())
+    .add(_("Aliases"), get_aliases());
+  
+  if (!detail_name.empty())
+    {
+      std::string detail_key = _("Container (%1)");
+      std::string::size_type pos = detail_key.find_first_of("%1", 0, 2);
+      if (pos != std::string::npos)
+	detail_key.replace(pos, 2, detail_name.c_str());
+      detail.add(detail_key, get_container());
+    }
+
+  detail
     .add(_("Environment Filter"), get_environment_filter())
     .add(_("Run Setup Scripts"), get_run_setup_scripts())
     .add(_("Run Execution Scripts"), get_run_exec_scripts())
@@ -521,8 +553,10 @@ sbuild::chroot::get_keyfile (keyfile& keyfile) const
 {
   keyfile.remove_group(get_name());
 
-  keyfile::set_object_value(*this, &chroot::get_chroot_type,
-			    keyfile, get_name(), "type");
+  std::string type, container_key;
+  get_chroot_strings(&type, &container_key, NULL);
+
+  keyfile.set_value(get_name(), "type", type);
 
   keyfile::set_object_value(*this, &chroot::get_active,
 			    keyfile, get_name(), "active");
@@ -542,6 +576,10 @@ sbuild::chroot::get_keyfile (keyfile& keyfile) const
   keyfile::set_object_list_value(*this, &chroot::get_aliases,
 				 keyfile, get_name(), "aliases");
 
+  if (!container_key.empty())
+    keyfile::set_object_value(*this, &chroot::get_container,
+			      keyfile, get_name(), container_key);
+
   keyfile::set_object_value(*this, &chroot::get_environment_filter,
 			    keyfile, get_name(), "environment-filter");
 
@@ -671,4 +709,15 @@ sbuild::chroot::set_keyfile (keyfile const& keyfile,
 			    keyfile, get_name(), "personality",
 			    keyfile::PRIORITY_OPTIONAL);
   used_keys.push_back("personality");
+
+  std::string container_key;
+  get_chroot_strings(NULL, &container_key, NULL);
+  if (!container_key.empty())
+    {
+      keyfile::get_object_value(*this, &chroot::set_container,
+				keyfile, get_name(), container_key,
+				keyfile::PRIORITY_REQUIRED);
+      used_keys.push_back(container_key);
+    }
 }
+
diff --git a/sbuild/sbuild-chroot.h b/sbuild/sbuild-chroot.h
index 35292f2..6bbbe32 100644
--- a/sbuild/sbuild-chroot.h
+++ b/sbuild/sbuild-chroot.h
@@ -485,12 +485,16 @@ namespace sbuild
     set_persona (personality const& persona);
 
     /**
-     * Get the type of the chroot.
+     * Gets the container config names.
      *
-     * @returns the chroot type.
+     * @param type the chroot type.
+     * @param key_name the name of the key, which stores the container.
+     * @param detail_name the name of the detail for the container.
      */
-    virtual std::string const&
-    get_chroot_type () const = 0;
+    virtual void
+    get_chroot_strings (std::string *type,
+			std::string *key_name,
+			std::string *detail_name) const = 0;
 
     /**
      * Set environment.  Set the environment that the setup scripts
diff --git a/test/sbuild-chroot-block-device.cc b/test/sbuild-chroot-block-device.cc
index b83f8e8..88ed25f 100644
--- a/test/sbuild-chroot-block-device.cc
+++ b/test/sbuild-chroot-block-device.cc
@@ -46,7 +46,7 @@ class test_chroot_block_device : public test_chroot_base<chroot_block_device>
   CPPUNIT_TEST_SUITE(test_chroot_block_device);
   CPPUNIT_TEST(test_device);
   CPPUNIT_TEST(test_mount_options);
-  CPPUNIT_TEST(test_chroot_type);
+  CPPUNIT_TEST(test_chroot_strings);
   CPPUNIT_TEST(test_setup_env);
   CPPUNIT_TEST(test_session_flags);
   CPPUNIT_TEST(test_print_details);
@@ -84,9 +84,14 @@ public:
     CPPUNIT_ASSERT(c->get_mount_options() == "-o opt1,opt2");
   }
 
-  void test_chroot_type()
+  void test_chroot_strings()
   {
-    CPPUNIT_ASSERT(chroot->get_chroot_type() == "block-device");
+    std::string type, key_name, detail_name;
+    chroot->get_chroot_strings(&type, &key_name, &detail_name);
+    
+    CPPUNIT_ASSERT(type == "block-device");
+    CPPUNIT_ASSERT(key_name == "device");
+    CPPUNIT_ASSERT(detail_name == "Device");
   }
 
   void test_setup_env()
@@ -95,6 +100,8 @@ public:
     expected.add("CHROOT_TYPE",           "block-device");
     expected.add("CHROOT_NAME",           "test-name");
     expected.add("CHROOT_DESCRIPTION",    "test-description");
+    expected.add("CHROOT_CONTAINER",      "");
+    expected.add("CHROOT_LOCATION",       "");
     expected.add("CHROOT_MOUNT_LOCATION", "/mnt/mount-location");
     expected.add("CHROOT_PATH",           "/mnt/mount-location");
     expected.add("CHROOT_DEVICE",         "/dev/testdev");
diff --git a/test/sbuild-chroot-directory.cc b/test/sbuild-chroot-directory.cc
index 44739bf..2e9f088 100644
--- a/test/sbuild-chroot-directory.cc
+++ b/test/sbuild-chroot-directory.cc
@@ -19,6 +19,7 @@
 #include <config.h>
 
 #include <sbuild/sbuild-chroot-directory.h>
+#include <sbuild/sbuild-chroot-config.h>
 
 #include "test-helpers.h"
 #include "test-sbuild-chroot.h"
@@ -45,7 +46,7 @@ class test_chroot_directory : public test_chroot_base<chroot_directory>
 {
   CPPUNIT_TEST_SUITE(test_chroot_directory);
   CPPUNIT_TEST(test_location);
-  CPPUNIT_TEST(test_chroot_type);
+  CPPUNIT_TEST(test_chroot_strings);
   CPPUNIT_TEST(test_setup_env);
   CPPUNIT_TEST(test_setup_env2);
   CPPUNIT_TEST(test_session_flags);
@@ -81,9 +82,14 @@ public:
     CPPUNIT_ASSERT(chroot->get_mount_location() == "");
   }
 
-  void test_chroot_type()
+  void test_chroot_strings()
   {
-    CPPUNIT_ASSERT(chroot->get_chroot_type() == "directory");
+    std::string type, key_name, detail_name;
+    chroot->get_chroot_strings(&type, &key_name, &detail_name);
+    
+    CPPUNIT_ASSERT(type == "directory");
+    CPPUNIT_ASSERT(key_name == "location");
+    CPPUNIT_ASSERT(detail_name == "Location");
   }
 
   void test_setup_env()
diff --git a/test/sbuild-chroot-file.cc b/test/sbuild-chroot-file.cc
index 430ce7d..93c8c4f 100644
--- a/test/sbuild-chroot-file.cc
+++ b/test/sbuild-chroot-file.cc
@@ -45,7 +45,7 @@ class test_chroot_file : public test_chroot_base<chroot_file>
 {
   CPPUNIT_TEST_SUITE(test_chroot_file);
   CPPUNIT_TEST(test_file);
-  CPPUNIT_TEST(test_chroot_type);
+  CPPUNIT_TEST(test_chroot_strings);
   CPPUNIT_TEST(test_setup_env);
   CPPUNIT_TEST(test_session_flags);
   CPPUNIT_TEST(test_print_details);
@@ -73,9 +73,14 @@ public:
     CPPUNIT_ASSERT(c->get_container() == "/srv/chroot-images/unstable.tar.gz");
   }
 
-  void test_chroot_type()
+  void test_chroot_strings()
   {
-    CPPUNIT_ASSERT(chroot->get_chroot_type() == "file");
+    std::string type, key_name, detail_name;
+    chroot->get_chroot_strings(&type, &key_name, &detail_name);
+    
+    CPPUNIT_ASSERT(type == "file");
+    CPPUNIT_ASSERT(key_name == "file");
+    CPPUNIT_ASSERT(detail_name == "File");
   }
 
   void test_setup_env()
diff --git a/test/sbuild-chroot-lvm-snapshot.cc b/test/sbuild-chroot-lvm-snapshot.cc
index 9ae57de..d269abe 100644
--- a/test/sbuild-chroot-lvm-snapshot.cc
+++ b/test/sbuild-chroot-lvm-snapshot.cc
@@ -47,7 +47,7 @@ class test_chroot_lvm_snapshot : public test_chroot_base<chroot_lvm_snapshot>
   CPPUNIT_TEST_SUITE(test_chroot_lvm_snapshot);
   CPPUNIT_TEST(test_snapshot_device);
   CPPUNIT_TEST(test_snapshot_options);
-  CPPUNIT_TEST(test_chroot_type);
+  CPPUNIT_TEST(test_chroot_strings);
   CPPUNIT_TEST(test_setup_env);
   CPPUNIT_TEST(test_session_flags);
   CPPUNIT_TEST(test_print_details);
@@ -87,9 +87,14 @@ public:
     CPPUNIT_ASSERT(c->get_snapshot_options() == "-o opt1,opt2");
   }
 
-  void test_chroot_type()
+  void test_chroot_strings()
   {
-    CPPUNIT_ASSERT(chroot->get_chroot_type() == "lvm-snapshot");
+    std::string type, key_name, detail_name;
+    chroot->get_chroot_strings(&type, &key_name, &detail_name);
+    
+    CPPUNIT_ASSERT(type == "lvm-snapshot");
+    CPPUNIT_ASSERT(key_name == "device");
+    CPPUNIT_ASSERT(detail_name == "LVM Snapshot Device");
   }
 
   void test_setup_env()
diff --git a/test/sbuild-chroot-plain.cc b/test/sbuild-chroot-plain.cc
index 2bb23d9..8b2572d 100644
--- a/test/sbuild-chroot-plain.cc
+++ b/test/sbuild-chroot-plain.cc
@@ -45,7 +45,7 @@ class test_chroot_plain : public test_chroot_base<chroot_plain>
 {
   CPPUNIT_TEST_SUITE(test_chroot_plain);
   CPPUNIT_TEST(test_location);
-  CPPUNIT_TEST(test_chroot_type);
+  CPPUNIT_TEST(test_chroot_strings);
   CPPUNIT_TEST(test_setup_env);
   CPPUNIT_TEST(test_print_details);
   CPPUNIT_TEST(test_print_config);
@@ -75,9 +75,14 @@ public:
     CPPUNIT_ASSERT(chroot->get_mount_location() == "");
   }
 
-  void test_chroot_type()
+  void test_chroot_strings()
   {
-    CPPUNIT_ASSERT(chroot->get_chroot_type() == "plain");
+    std::string type, key_name, detail_name;
+    chroot->get_chroot_strings(&type, &key_name, &detail_name);
+    
+    CPPUNIT_ASSERT(type == "plain");
+    CPPUNIT_ASSERT(key_name == "location");
+    CPPUNIT_ASSERT(detail_name == "Location");
   }
 
   void test_setup_env()
diff --git a/test/sbuild-chroot.cc b/test/sbuild-chroot.cc
index dd8d709..1c5efba 100644
--- a/test/sbuild-chroot.cc
+++ b/test/sbuild-chroot.cc
@@ -44,9 +44,18 @@ public:
   clone () const
   { return ptr(new basic_chroot(*this)); }
 
-  virtual std::string const&
-  get_chroot_type () const
-  { static const std::string type("test"); return type; }
+  virtual void
+  get_chroot_strings (std::string *type,
+		      std::string *key_name,
+		      std::string *detail_name) const
+  {
+    if (type != NULL)
+      *type = "test-type";
+    if (key_name != NULL)
+      *key_name = "test-key";
+    if (detail_name != NULL)
+      *detail_name = "Test Detail";
+  }
 
   virtual void
   setup_env (sbuild::environment& env)
@@ -82,7 +91,7 @@ class test_chroot : public test_chroot_base<basic_chroot>
   CPPUNIT_TEST(test_active);
   CPPUNIT_TEST(test_run_setup_scripts);
   CPPUNIT_TEST(test_run_exec_scripts);
-  CPPUNIT_TEST(test_chroot_type);
+  CPPUNIT_TEST(test_chroot_strings);
   CPPUNIT_TEST(test_setup_env);
   CPPUNIT_TEST(test_session_flags);
   CPPUNIT_TEST(test_print_details);
@@ -194,15 +203,20 @@ public:
     CPPUNIT_ASSERT(chroot->get_run_exec_scripts() == false);
   }
 
-  void test_chroot_type()
+  void test_chroot_strings()
   {
-    CPPUNIT_ASSERT(chroot->get_chroot_type() == "test");
+    std::string type, key_name, detail_name;
+    chroot->get_chroot_strings(&type, &key_name, &detail_name);
+    
+    CPPUNIT_ASSERT(type == "test-type");
+    CPPUNIT_ASSERT(key_name == "test-key");
+    CPPUNIT_ASSERT(detail_name == "Test Detail");
   }
 
   void test_setup_env()
   {
     sbuild::environment expected;
-    expected.add("CHROOT_TYPE",           "test");
+    expected.add("CHROOT_TYPE",           "test-type");
     expected.add("CHROOT_NAME",           "test-name");
     expected.add("CHROOT_DESCRIPTION",    "test-description");
     expected.add("CHROOT_MOUNT_LOCATION", "/mnt/mount-location");
-- 
1.6.2.1




More information about the Buildd-tools-devel mailing list