Expose builtin architectures at class level
authorKlaus Kämpf <kkaempf@suse.de>
Mon, 8 Nov 2010 15:46:53 +0000 (16:46 +0100)
committerKlaus Kämpf <kkaempf@suse.de>
Mon, 8 Nov 2010 15:46:53 +0000 (16:46 +0100)
swig/Arch.i
swig/python/tests/arch.py
swig/ruby/tests/arch.rb

index 0675ad9..0651b17 100644 (file)
@@ -3,6 +3,24 @@
  *
  * Architecture definitions
  *
+ * Document-class: Arch
+ * Instances of Arch represent architecture and compatibility.
+ * The system has an architecture (i.e. x86_64) and so does every
+ * Resolvable.
+ *
+ * Arch#compatible_with is used to detect compatible architectures.
+ * 'noarch' is compatible with any system architecture.
+ *
+ * There is no limit to architecture specifiers, any string can be
+ * passed to the Arch constructor.
+ * However, there is a set of architectures built into libzypp.
+ * Arch#builtin? returns true for an architecture from the builtin set.
+ *
+ * == Usage
+ *   arch = Arch.new("i686")
+ *
+ *   arch.builtin? -> true
+ *
  */
 
 %nodefault zypp::Arch;
@@ -19,9 +37,24 @@ class Arch {
   ~Arch() {
     delete $self;
   }
+  
+  # all the standard architectures
+  static Arch noarch() { return zypp::Arch_noarch; }
+  static Arch i386() { return zypp::Arch_i386; }
+  static Arch i486() { return zypp::Arch_i486; }
+  static Arch i586() { return zypp::Arch_i586; }
+  static Arch i686() { return zypp::Arch_i686; }
+  static Arch x86_64() { return zypp::Arch_x86_64; }
+  static Arch ia64() { return zypp::Arch_ia64; }
+  static Arch ppc() { return zypp::Arch_ppc; }
+  static Arch ppc64() { return zypp::Arch_ppc64; }
+  static Arch s390() { return zypp::Arch_s390; }
+  static Arch s390x() { return zypp::Arch_s390x; }
+
 #if defined(SWIGRUBY)
 %typemap(out) int is_builtin
    "$result = $1 ? Qtrue : Qfalse;";
+%rename("builtin?") builtin;
 #endif
   /*
    * Whether this is a builtin (or known) architecture.
@@ -33,6 +66,7 @@ class Arch {
 #if defined(SWIGRUBY)
 %typemap(out) int compatible_with
    "$result = $1 ? Qtrue : Qfalse;";
+%rename("compatible_with?") compatible_with;
 #endif
   /*
    * Check if this architecture is compatible with another one
index 01751b0..4451da8 100644 (file)
@@ -28,5 +28,16 @@ class TestSequenceFunctions(unittest.TestCase):
     assert "xyzzy" == z.__str__()
     assert not z.is_builtin()
 
+    assert Arch("noarch") == Arch.noarch()
+    assert a, Arch.i386()
+    assert b, Arch.i486()
+    assert Arch("i586") == Arch.i586()
+    assert Arch("i686") == Arch.i686()
+    assert Arch("x86_64") == Arch.x86_64()
+    assert Arch("ia64") == Arch.ia64()
+    assert Arch("ppc") == Arch.ppc()
+    assert Arch("ppc64") == Arch.ppc64()
+    assert Arch("s390") == Arch.s390()
+    assert Arch("s390x") == Arch.s390x()
 if __name__ == '__main__':
   unittest.main()
index 95d3cef..e9a8155 100644 (file)
@@ -14,22 +14,40 @@ end
 class ArchTest < Test::Unit::TestCase
   include Zypp
   def test_arch
+    # define i386, a builtin
+    
     a = Arch.new("i386")
     assert a
     assert_equal "i386", a.to_s
     assert a.is_builtin
     
+    # i486 is 'bigger' than i386
+    
     b = Arch.new("i486")
     assert b
     assert_equal "i486", b.to_s
     assert b.is_builtin
     assert_equal a, b.base_arch
     assert a < b
-    assert a.compatible_with(b)
+    assert a.compatible_with?(b)
 
+    # A new, adventurous architecture
     z = Arch.new("xyzzy")
     assert z
     assert_equal "xyzzy", z.to_s
     assert !z.is_builtin
+    
+    # predefined archs
+    assert_equal Arch.new("noarch"), Arch.noarch 
+    assert_equal a, Arch.i386
+    assert_equal b, Arch.i486
+    assert_equal Arch.new("i586"), Arch.i586
+    assert_equal Arch.new("i686"), Arch.i686
+    assert_equal Arch.new("x86_64"), Arch.x86_64
+    assert_equal Arch.new("ia64"), Arch.ia64
+    assert_equal Arch.new("ppc"), Arch.ppc
+    assert_equal Arch.new("ppc64"), Arch.ppc64
+    assert_equal Arch.new("s390"), Arch.s390
+    assert_equal Arch.new("s390x"), Arch.s390x
   end
 end