diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | python/contents.cc | 9 | ||||
-rwxr-xr-x | python/contents_TEST.py | 12 | ||||
-rw-r--r-- | ruby/contents.cc | 49 | ||||
-rw-r--r-- | ruby/contents_TEST.rb | 38 |
5 files changed, 90 insertions, 19 deletions
diff --git a/.gitignore b/.gitignore index 8106d60cf..5be087bfc 100644 --- a/.gitignore +++ b/.gitignore @@ -266,6 +266,7 @@ tags /paludis/ihateautomake.cc /paludis/name_TEST /paludis/paludis.hh +/paludis/partitioning_TEST /paludis/repositories/accounts/accounts_repository_TEST /paludis/repositories/e/aa_visitor_TEST /paludis/repositories/e/dep_parser_TEST diff --git a/python/contents.cc b/python/contents.cc index a018aa40c..70594397f 100644 --- a/python/contents.cc +++ b/python/contents.cc @@ -80,8 +80,10 @@ void expose_contents() ( "ContentsFileEntry", "A file contents entry.", - bp::init<const FSPath &>("__init__(location)") - ); + bp::init<const FSPath &, const std::string &>("__init__(location, part)") + ) + .def("part_key", &ContentsFileEntry::part_key) + ; /** * ContentsDirEntry @@ -110,12 +112,13 @@ void expose_contents() ( "ContentsSymEntry", "A sym contents entry.", - bp::init<const FSPath &, const std::string &>("__init__(location, target_string)") + bp::init<const FSPath &, const std::string &, const std::string &>("__init__(location, target_string, part)") ) .def("target_key", &ContentsSymEntry::target_key, "The target_key, which will not be None, holds the symlink's target (as per readlink)." ) + .def("part_key", &ContentsSymEntry::part_key) ; /** diff --git a/python/contents_TEST.py b/python/contents_TEST.py index 3e2c49bfb..03327b799 100755 --- a/python/contents_TEST.py +++ b/python/contents_TEST.py @@ -26,10 +26,11 @@ class TestCase_Contents(unittest.TestCase): self.assertRaises(Exception, ContentsEntry) def test_02_file_entry(self): - e = ContentsFileEntry("/foo") + e = ContentsFileEntry("/foo", "bar") self.assert_(isinstance(e, ContentsEntry)) self.assertEquals(e.location_key().parse_value(), "/foo") + self.assertEquals(e.part_key().parse_value(), "bar") def test_03_dir_entry(self): e = ContentsDirEntry("/foo") @@ -44,16 +45,17 @@ class TestCase_Contents(unittest.TestCase): self.assertEquals(e.location_key().parse_value(), "/foo") def test_07_sym_entry(self): - e = ContentsSymEntry("/foo", "/blah") + e = ContentsSymEntry("/foo", "/blah", "baz") self.assert_(isinstance(e, ContentsEntry)) self.assertEquals(e.location_key().parse_value(), "/foo") self.assertEquals(e.target_key().parse_value(), "/blah") + self.assertEquals(e.part_key().parse_value(), "baz") def test_08_contents(self): entries = [] - entries.append(ContentsSymEntry("/foo", "/blah")) - entries.append(ContentsFileEntry("/foo")) + entries.append(ContentsSymEntry("/foo", "/blah", "x")) + entries.append(ContentsFileEntry("/foo", "x")) entries.append(ContentsOtherEntry("/dev/foo")) entries.append(ContentsDirEntry("/bar")) @@ -66,6 +68,8 @@ class TestCase_Contents(unittest.TestCase): self.assertEquals(type(entry), type(entries[i])) if i==0: self.assertEquals(entry.target_key().parse_value(), entries[i].target_key().parse_value()) + if i==0 or i==1: + self.assertEquals(entry.part_key().parse_value(), entries[i].part_key().parse_value()) if i>3: self.assertEquals("TOO MANY ENTRIES", "OK") diff --git a/ruby/contents.cc b/ruby/contents.cc index 0dd642a89..04f4afe97 100644 --- a/ruby/contents.cc +++ b/ruby/contents.cc @@ -192,14 +192,14 @@ namespace } }; - VALUE contents_sym_entry_new(int argc, VALUE * argv, VALUE self) + VALUE contents_file_entry_new(int argc, VALUE * argv, VALUE self) { std::shared_ptr<const ContentsEntry> * ptr(0); try { if (2 == argc) { - ptr = new std::shared_ptr<const ContentsEntry>(std::make_shared<ContentsSymEntry>( + ptr = new std::shared_ptr<const ContentsEntry>(std::make_shared<ContentsFileEntry>( FSPath(StringValuePtr(argv[0])), StringValuePtr(argv[1]))); } else @@ -217,6 +217,31 @@ namespace } } + VALUE contents_sym_entry_new(int argc, VALUE * argv, VALUE self) + { + std::shared_ptr<const ContentsEntry> * ptr(0); + try + { + if (3 == argc) + { + ptr = new std::shared_ptr<const ContentsEntry>(std::make_shared<ContentsSymEntry>( + FSPath(StringValuePtr(argv[0])), StringValuePtr(argv[1]), StringValuePtr(argv[2]))); + } + else + { + rb_raise(rb_eArgError, "ContentsSymEntry expects three arguments, but got %d",argc); + } + VALUE tdata(Data_Wrap_Struct(self, 0, &Common<std::shared_ptr<const ContentsEntry> >::free, ptr)); + rb_obj_call_init(tdata, argc, argv); + return tdata; + } + catch (const std::exception & e) + { + delete ptr; + exception_to_ruby_exception(e); + } + } + /* * Document-method: location_key * @@ -230,6 +255,14 @@ namespace return metadata_key_to_value((*ptr)->location_key()); } + static VALUE + contents_file_entry_part_key(VALUE self) + { + std::shared_ptr<const ContentsEntry> * ptr; + Data_Get_Struct(self, std::shared_ptr<const ContentsEntry>, ptr); + return metadata_key_to_value((std::static_pointer_cast<const ContentsFileEntry>(*ptr))->part_key()); + } + /* * Document-method: target_key * @@ -243,6 +276,14 @@ namespace return metadata_key_to_value((std::static_pointer_cast<const ContentsSymEntry>(*ptr))->target_key()); } + static VALUE + contents_sym_entry_part_key(VALUE self) + { + std::shared_ptr<const ContentsEntry> * ptr; + Data_Get_Struct(self, std::shared_ptr<const ContentsEntry>, ptr); + return metadata_key_to_value((std::static_pointer_cast<const ContentsSymEntry>(*ptr))->part_key()); + } + /* * call-seq: * each_metadata {|key| block } -> Nil @@ -296,7 +337,8 @@ namespace * A file ContentsEntry */ c_contents_file_entry = rb_define_class_under(paludis_module(), "ContentsFileEntry", c_contents_entry); - rb_define_singleton_method(c_contents_file_entry, "new", RUBY_FUNC_CAST((&ContentsNew<ContentsFileEntry>::contents_entry_new)), -1); + rb_define_singleton_method(c_contents_file_entry, "new", RUBY_FUNC_CAST(&contents_file_entry_new), -1); + rb_define_method(c_contents_file_entry, "part_key", RUBY_FUNC_CAST(&contents_file_entry_part_key), 0); /* * Document-class: Paludis::ContentsDirEntry @@ -323,6 +365,7 @@ namespace c_contents_sym_entry = rb_define_class_under(paludis_module(), "ContentsSymEntry", c_contents_entry); rb_define_singleton_method(c_contents_sym_entry, "new", RUBY_FUNC_CAST(&contents_sym_entry_new), -1); rb_define_method(c_contents_sym_entry, "target_key", RUBY_FUNC_CAST(&contents_sym_entry_target_key), 0); + rb_define_method(c_contents_sym_entry, "part_key", RUBY_FUNC_CAST(&contents_sym_entry_part_key), 0); } } diff --git a/ruby/contents_TEST.rb b/ruby/contents_TEST.rb index 926f85d09..bd3a28116 100644 --- a/ruby/contents_TEST.rb +++ b/ruby/contents_TEST.rb @@ -31,7 +31,7 @@ module Paludis class TestCase_ContentsFileEntry < Test::Unit::TestCase def get_ce - ContentsFileEntry.new('test') + ContentsFileEntry.new('test', 'foo') end def test_create @@ -44,23 +44,33 @@ module Paludis end assert_raise ArgumentError do - ContentsFileEntry.new('a','b') + ContentsFileEntry.new('a') end assert_raise TypeError do - ContentsFileEntry.new(1) + ContentsFileEntry.new(1, 'b') + end + + assert_raise TypeError do + ContentsFileEntry.new('a', 2) end end def test_respond_to ce = get_ce assert_respond_to ce, :location_key + assert_respond_to ce, :part_key end def test_name ce = get_ce assert_equal 'test', ce.location_key.parse_value end + + def test_part + ce = get_ce + assert_equal 'foo', ce.part_key.parse_value + end end class TestCase_ContentsDirEntry < Test::Unit::TestCase @@ -133,7 +143,7 @@ module Paludis class TestCase_ContentsSymEntry < Test::Unit::TestCase def get_ce - ContentsSymEntry.new('test_name', 'test_target') + ContentsSymEntry.new('test_name', 'test_target', 'test_part') end def test_create @@ -150,15 +160,19 @@ module Paludis end assert_raise ArgumentError do - ContentsSymEntry.new('a','b','c') + ContentsSymEntry.new('a','b') end assert_raise TypeError do - ContentsSymEntry.new('a',1) + ContentsSymEntry.new('a','b',1) end assert_raise TypeError do - ContentsSymEntry.new(1,'b') + ContentsSymEntry.new('a',1,'c') + end + + assert_raise TypeError do + ContentsSymEntry.new(1,'b','c') end end @@ -166,6 +180,7 @@ module Paludis ce = get_ce assert_respond_to ce, :location_key assert_respond_to ce, :target_key + assert_respond_to ce, :part_key end def test_name @@ -177,14 +192,19 @@ module Paludis ce = get_ce assert_equal 'test_target', ce.target_key.parse_value end + + def test_part + ce = get_ce + assert_equal 'test_part', ce.part_key.parse_value + end end class TestCase_Contents < Test::Unit::TestCase def get_cfe - ContentsFileEntry.new('test') + ContentsFileEntry.new('test', 'foo') end def get_cse - ContentsSymEntry.new('test_name', 'test_target') + ContentsSymEntry.new('test_name', 'test_target', 'foo') end def get_c |