summaryrefslogtreecommitdiffstats
path: root/dom/system/gonk/tests/test_ril_worker_cdma_info_rec.js
blob: 335c0c403d7dc82a3197722ddaa376a6f16a0784 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this);

function run_test() {
  run_next_test();
}

/**
 * Helper function.
 */
function newWorkerWithParcel(parcelBuf) {
  let worker = newWorker({
    postRILMessage: function(data) {
      // Do nothing
    },
    postMessage: function(message) {
      // Do nothing
    }
  });

  let index = 0; // index for read
  let buf = parcelBuf;

  let context = worker.ContextPool._contexts[0];
  context.Buf.readUint8 = function() {
    return buf[index++];
  };

  context.Buf.readUint16 = function() {
    return buf[index++];
  };

  context.Buf.readInt32 = function() {
    return buf[index++];
  };

  context.Buf.seekIncoming = function(offset) {
    index += offset / context.Buf.UINT32_SIZE;
  };

  return worker;
}

// Test CDMA information record decoder.

/**
 * Verify decoder for type DISPLAY
 */
add_test(function test_display() {
  let worker = newWorkerWithParcel([
                0x01, // one inforemation record
                0x00, // type: display
                0x09, // length: 9
                0x54, 0x65, 0x73, 0x74, 0x20, 0x49, 0x6E, 0x66,
                0x6F, 0x00]);
  let context = worker.ContextPool._contexts[0];
  let helper = context.CdmaPDUHelper;
  let records = helper.decodeInformationRecord();

  equal(records[0].display, "Test Info");

  run_next_test();
});

/**
 * Verify decoder for type EXTENDED DISPLAY
 */
add_test(function test_extended_display() {
  let worker = newWorkerWithParcel([
                0x01, // one inforemation record
                0x07, // type: extended display
                0x12, // length: 18
                0x54, 0x65, 0x73, 0x74, 0x20, 0x45, 0x78, 0x74,
                0x65, 0x6E, 0x64, 0x65, 0x64, 0x20, 0x49, 0x6E,
                0x66, 0x6F, 0x00, 0x00]);
  let context = worker.ContextPool._contexts[0];
  let helper = context.CdmaPDUHelper;
  let records = helper.decodeInformationRecord();

  equal(records[0].display, "Test Extended Info");

  run_next_test();
});

/**
 * Verify decoder for mixed type
 */
add_test(function test_mixed() {
  let worker = newWorkerWithParcel([
                0x02, // two inforemation record
                0x00, // type: display
                0x0B, // length: 11
                0x54, 0x65, 0x73, 0x74, 0x20, 0x49, 0x6E, 0x66,
                0x6F, 0x20, 0x31, 0x00,
                0x07, // type: extended display
                0x0B, // length: 11
                0x54, 0x65, 0x73, 0x74, 0x20, 0x49, 0x6E, 0x66,
                0x6F, 0x20, 0x32, 0x00]);
  let context = worker.ContextPool._contexts[0];
  let helper = context.CdmaPDUHelper;
  let records = helper.decodeInformationRecord();

  equal(records[0].display, "Test Info 1");
  equal(records[1].display, "Test Info 2");

  run_next_test();
});

/**
 * Verify decoder for multiple types
 */
add_test(function test_multiple() {
  let worker = newWorkerWithParcel([
                0x02, // two inforemation record
                0x00, // type: display
                0x0B, // length: 11
                0x54, 0x65, 0x73, 0x74, 0x20, 0x49, 0x6E, 0x66,
                0x6F, 0x20, 0x31, 0x00,
                0x00, // type: display
                0x0B, // length: 11
                0x54, 0x65, 0x73, 0x74, 0x20, 0x49, 0x6E, 0x66,
                0x6F, 0x20, 0x32, 0x00]);
  let context = worker.ContextPool._contexts[0];
  let helper = context.CdmaPDUHelper;
  let records = helper.decodeInformationRecord();

  equal(records[0].display, "Test Info 1");
  equal(records[1].display, "Test Info 2");

  run_next_test();
});

/**
 * Verify decoder for Signal Type
 */
add_test(function test_signal() {
  let worker = newWorkerWithParcel([
                0x01,   // one inforemation record
                0x04,   // type: signal
                0x01,   // isPresent: non-zero
                0x00,   // signalType: Tone signal (00)
                0x01,   // alertPitch: High pitch
                0x03]); // signal: Abbreviated intercept (000011)
  let context = worker.ContextPool._contexts[0];
  let helper = context.CdmaPDUHelper;
  let records = helper.decodeInformationRecord();

  equal(records[0].signal.type, 0x00);
  equal(records[0].signal.alertPitch, 0x01);
  equal(records[0].signal.signal, 0x03);

  run_next_test();
});

/**
 * Verify decoder for Signal Type for Not Presented
 */
add_test(function test_signal_not_present() {
  let worker = newWorkerWithParcel([
                0x01,   // one inforemation record
                0x04,   // type: signal
                0x00,   // isPresent: zero
                0x00,   // signalType: Tone signal (00)
                0x01,   // alertPitch: High pitch
                0x03]); // signal: Abbreviated intercept (000011)
  let context = worker.ContextPool._contexts[0];
  let helper = context.CdmaPDUHelper;
  let records = helper.decodeInformationRecord();

  equal(records.length, 0);

  run_next_test();
});

/**
 * Verify decoder for Line Control
 */
add_test(function test_line_control() {
  let worker = newWorkerWithParcel([
                0x01,   // one inforemation record
                0x06,   // type: line control
                0x01,   // polarity included
                0x00,   // not toggled
                0x01,   // reversed
                0xFF]); // Power denial timeout: 255 * 5 ms
  let context = worker.ContextPool._contexts[0];
  let helper = context.CdmaPDUHelper;
  let records = helper.decodeInformationRecord();

  equal(records[0].lineControl.polarityIncluded, 1);
  equal(records[0].lineControl.toggle, 0);
  equal(records[0].lineControl.reverse, 1);
  equal(records[0].lineControl.powerDenial, 255);

  run_next_test();
});

/**
 * Verify decoder for CLIR Cause
 */
add_test(function test_clir() {
  let worker = newWorkerWithParcel([
                0x01,   // one inforemation record
                0x08,   // type: clir
                0x01]); // cause: Rejected by user
  let context = worker.ContextPool._contexts[0];
  let helper = context.CdmaPDUHelper;
  let records = helper.decodeInformationRecord();

  equal(records[0].clirCause, 1);

  run_next_test();
});

/**
 * Verify decoder for Audio Control
 */
add_test(function test_clir() {
  let worker = newWorkerWithParcel([
                0x01,   // one inforemation record
                0x0A,   // type: audio control
                0x01,   // uplink
                0xFF]); // downlink
  let context = worker.ContextPool._contexts[0];
  let helper = context.CdmaPDUHelper;
  let records = helper.decodeInformationRecord();

  equal(records[0].audioControl.upLink, 1);
  equal(records[0].audioControl.downLink, 255);

  run_next_test();
});