@@ -45,61 +45,41 @@ func TestFindPackage(t *testing.T) {
45
45
}
46
46
}
47
47
48
- func TestFindType (t * testing.T ) {
48
+ func TestGetResourceNil (t * testing.T ) {
49
49
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 )
60
53
}
61
54
}
62
55
63
- func TestFindTypeJa (t * testing.T ) {
56
+ func TestGetResourceDefault (t * testing.T ) {
64
57
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 )
77
61
}
78
62
}
79
63
80
- func TestFindTypeEn (t * testing.T ) {
64
+ func TestGetResourceJA (t * testing.T ) {
81
65
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' },
90
68
}
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 )
94
72
}
95
73
}
96
74
97
- func TestGetResource (t * testing.T ) {
75
+ func TestGetResourceEN (t * testing.T ) {
98
76
tableFile := loadTestData ()
99
- config := & ResTableConfig {}
77
+ config := & ResTableConfig {
78
+ Language : [2 ]uint8 {'e' , 'n' },
79
+ }
100
80
val , _ := tableFile .GetResource (ResId (0x7f040000 ), config )
101
81
if val != "FireworksMeasure" {
102
- t .Errorf (" got %v want \" \" " , val )
82
+ t .Errorf (` got %v want "FireworksMeasure"` , val )
103
83
}
104
84
}
105
85
@@ -108,6 +88,21 @@ var isMoreSpecificThanTests = []struct {
108
88
other * ResTableConfig
109
89
expected bool
110
90
}{
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
+ },
111
106
{
112
107
me : & ResTableConfig {},
113
108
other : & ResTableConfig {},
@@ -124,7 +119,9 @@ var isMoreSpecificThanTests = []struct {
124
119
expected : true ,
125
120
},
126
121
{
127
- me : & ResTableConfig {Language : [2 ]byte {'j' , 'a' }},
122
+ me : & ResTableConfig {
123
+ Language : [2 ]uint8 {'j' , 'a' },
124
+ },
128
125
other : & ResTableConfig {},
129
126
expected : true ,
130
127
},
@@ -230,16 +227,16 @@ func TestIsMoreSpecificThan(t *testing.T) {
230
227
actual := tt .me .IsMoreSpecificThan (tt .other )
231
228
if actual != tt .expected {
232
229
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 )
234
231
} 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 )
236
233
}
237
234
}
238
235
239
236
if tt .expected {
240
237
// If 'me' is more specific than 'other', 'other' is not more specific than 'me'
241
238
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 )
243
240
}
244
241
}
245
242
}
@@ -447,16 +444,16 @@ func TestIsBetterThan(t *testing.T) {
447
444
actual := tt .me .IsBetterThan (tt .other , tt .require )
448
445
if actual != tt .expected {
449
446
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 )
451
448
} 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 )
453
450
}
454
451
}
455
452
456
453
if tt .expected {
457
454
// If 'me' is better than 'other', 'other' is not better than 'me'
458
455
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 )
460
457
}
461
458
}
462
459
}
0 commit comments