@@ -45,61 +45,41 @@ func TestFindPackage(t *testing.T) {
4545 }
4646}
4747
48- func TestFindType (t * testing.T ) {
48+ func TestGetResourceNil (t * testing.T ) {
4949 tableFile := loadTestData ()
50- p := tableFile .findPackage (0x7F )
51- id := 0x04
52- config := & ResTableConfig {}
53- tableType := p .findType (id , config )
54- if int (tableType .Header .Id ) != id {
55- t .Errorf ("got %v want %v" , tableType .Header .Id , id )
56- }
57- locale := tableType .Header .Config .Locale ()
58- if locale != "" {
59- t .Errorf ("got %v want \" \" " , locale )
50+ val , _ := tableFile .GetResource (ResId (0x7f040000 ), nil )
51+ if val != "FireworksMeasure" {
52+ t .Errorf (`got %v want "花火距離計算"` , val )
6053 }
6154}
6255
63- func TestFindTypeJa (t * testing.T ) {
56+ func TestGetResourceDefault (t * testing.T ) {
6457 tableFile := loadTestData ()
65- p := tableFile .findPackage (0x7F )
66- id := 0x04
67- config := & ResTableConfig {}
68- config .Language [0 ] = uint8 ('j' )
69- config .Language [1 ] = uint8 ('a' )
70- tableType := p .findType (id , config )
71- if int (tableType .Header .Id ) != id {
72- t .Errorf ("got %v want %v" , tableType .Header .Id , id )
73- }
74- locale := tableType .Header .Config .Locale ()
75- if locale != "ja" {
76- t .Errorf ("got %v want ja" , locale )
58+ val , _ := tableFile .GetResource (ResId (0x7f040000 ), & ResTableConfig {})
59+ if val != "FireworksMeasure" {
60+ t .Errorf (`got %v want "FireworksMeasure"` , val )
7761 }
7862}
7963
80- func TestFindTypeEn (t * testing.T ) {
64+ func TestGetResourceJA (t * testing.T ) {
8165 tableFile := loadTestData ()
82- p := tableFile .findPackage (0x7F )
83- id := 0x04
84- config := & ResTableConfig {}
85- config .Language [0 ] = uint8 ('e' )
86- config .Language [1 ] = uint8 ('n' )
87- tableType := p .findType (id , config )
88- if int (tableType .Header .Id ) != id {
89- t .Errorf ("got %v want %v" , tableType .Header .Id , id )
66+ config := & ResTableConfig {
67+ Language : [2 ]uint8 {'j' , 'a' },
9068 }
91- locale := tableType . Header . Config . Locale ( )
92- if locale != "" {
93- t .Errorf (" got %v want \" \" " , locale )
69+ val , _ := tableFile . GetResource ( ResId ( 0x7f040000 ), config )
70+ if val != "花火距離計算 " {
71+ t .Errorf (` got %v want "花火距離計算"` , val )
9472 }
9573}
9674
97- func TestGetResource (t * testing.T ) {
75+ func TestGetResourceEN (t * testing.T ) {
9876 tableFile := loadTestData ()
99- config := & ResTableConfig {}
77+ config := & ResTableConfig {
78+ Language : [2 ]uint8 {'e' , 'n' },
79+ }
10080 val , _ := tableFile .GetResource (ResId (0x7f040000 ), config )
10181 if val != "FireworksMeasure" {
102- t .Errorf (" got %v want \" \" " , val )
82+ t .Errorf (` got %v want "FireworksMeasure"` , val )
10383 }
10484}
10585
@@ -108,6 +88,21 @@ var isMoreSpecificThanTests = []struct {
10888 other * ResTableConfig
10989 expected bool
11090}{
91+ {
92+ me : nil ,
93+ other : nil ,
94+ expected : false ,
95+ },
96+ {
97+ me : nil ,
98+ other : & ResTableConfig {},
99+ expected : false ,
100+ },
101+ {
102+ me : & ResTableConfig {},
103+ other : nil ,
104+ expected : false ,
105+ },
111106 {
112107 me : & ResTableConfig {},
113108 other : & ResTableConfig {},
@@ -124,7 +119,9 @@ var isMoreSpecificThanTests = []struct {
124119 expected : true ,
125120 },
126121 {
127- me : & ResTableConfig {Language : [2 ]byte {'j' , 'a' }},
122+ me : & ResTableConfig {
123+ Language : [2 ]uint8 {'j' , 'a' },
124+ },
128125 other : & ResTableConfig {},
129126 expected : true ,
130127 },
@@ -230,16 +227,16 @@ func TestIsMoreSpecificThan(t *testing.T) {
230227 actual := tt .me .IsMoreSpecificThan (tt .other )
231228 if actual != tt .expected {
232229 if tt .expected {
233- t .Errorf ("%v is more specific than %v, but get false" , tt .me , tt .other )
230+ t .Errorf ("%+ v is more specific than %+ v, but get false" , tt .me , tt .other )
234231 } else {
235- t .Errorf ("%v is not more specific than %v, but get true" , tt .me , tt .other )
232+ t .Errorf ("%+ v is not more specific than %+ v, but get true" , tt .me , tt .other )
236233 }
237234 }
238235
239236 if tt .expected {
240237 // If 'me' is more specific than 'other', 'other' is not more specific than 'me'
241238 if tt .other .IsMoreSpecificThan (tt .me ) {
242- t .Errorf ("%v is not more specific than %v, but get true" , tt .other , tt .me )
239+ t .Errorf ("%+ v is not more specific than %+ v, but get true" , tt .other , tt .me )
243240 }
244241 }
245242 }
@@ -447,16 +444,16 @@ func TestIsBetterThan(t *testing.T) {
447444 actual := tt .me .IsBetterThan (tt .other , tt .require )
448445 if actual != tt .expected {
449446 if tt .expected {
450- t .Errorf ("%v is better than %v, but get false" , tt .me , tt .other )
447+ t .Errorf ("%+ v is better than %+ v, but get false (%+v) " , tt .me , tt .other , tt . require )
451448 } else {
452- t .Errorf ("%v is not better than %v, but get true" , tt .me , tt .other )
449+ t .Errorf ("%+ v is not better than %+ v, but get true (%+v) " , tt .me , tt .other , tt . require )
453450 }
454451 }
455452
456453 if tt .expected {
457454 // If 'me' is better than 'other', 'other' is not better than 'me'
458455 if tt .other .IsBetterThan (tt .me , tt .require ) {
459- t .Errorf ("%v is not better than %v, but get true" , tt .other , tt .me )
456+ t .Errorf ("%v is not better than %+ v, but get true (%+v) " , tt .other , tt .me , tt . require )
460457 }
461458 }
462459 }
0 commit comments