$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib') require 'test/unit' require 'og' require 'glue/logger' require 'glue/property' def VarChar(size) return String, :sql => "VARCHAR(#{ size })" end NotNull = {:sql => "NOT NULL"}.freeze Null = {:sql => "NULL"}.freeze # Property.type_checking = false module Test # :nodoc: all class Msg include Og::Unmanageable prop :owner_oid, Fixnum prop_accessor :val1, :val2, :val3, Fixnum, :sql => "smallint" prop_accessor :title, :body, String prop_accessor :test, String, :sql => "char(10) NOT NULL" prop_accessor :count, Fixnum prop_accessor :create_time, Time # a marshaled property prop_accessor :options, Array # property with macro arguments! prop_accessor :address, VarChar(30), NotNull def initialize @create_time = Time.now @options = [] end end class SubMsg < Msg # to avoid conflicts with tc_og.rb include Og::Unmanageable # duplicate definition with different type! prop_accessor :count, Float # another property prop_accessor :another, Fixnum end class C attr_accessor :name attr_accessor :description end class C property :name, String property :description, String end class TC_N_Properties < Test::Unit::TestCase def setup @msg1 = Msg.new end def teardown @msg1 = nil end def test_props # bug: props for subclasses. # bug: props propagated to base classes. assert(SubMsg.properties) assert_equal(Msg.properties.size(), SubMsg.properties.size() - 1) assert_equal(11, Msg.properties.size) assert_equal(12, SubMsg.properties.size) # bug: duplicate definition assert_equal(Float, SubMsg.properties.values.find { |p| :count == p.symbol }.klass) # dont force conversion @msg1.count = 2.4 assert_equal(Float, @msg1.count.class) # force conversion @msg1.__force_count(2.4) assert_equal(Fixnum, @msg1.count.class) end def test_macro_params sql = Msg.properties.values.find { |p| :address == p.symbol}.sql # FIXME: Temporarily dissabled. # assert_equal 'VARCHAR(30) NOT NULL', sql end def test_soc assert_equal String, C.ann.name.klass end end end