OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // Unit tests for SMS message creation | 4 // Unit tests for SMS message creation |
5 | 5 |
6 #include "sms_message.h" | 6 #include "sms_message.h" |
7 | 7 |
8 #include <gflags/gflags.h> | 8 #include <gflags/gflags.h> |
9 #include <glog/logging.h> | 9 #include <glog/logging.h> |
10 #include <gtest/gtest.h> | 10 #include <gtest/gtest.h> |
11 | 11 |
12 const uint8_t pdu[] = { | 12 const uint8_t pdu1[] = { |
13 0x07, 0x91, 0x21, 0x04, 0x44, 0x29, 0x61, 0xf4, | 13 0x07, 0x91, 0x21, 0x04, 0x44, 0x29, 0x61, 0xf4, |
14 0x04, 0x0b, 0x91, 0x61, 0x71, 0x95, 0x72, 0x91, | 14 0x04, 0x0b, 0x91, 0x61, 0x71, 0x95, 0x72, 0x91, |
15 0xf8, 0x00, 0x00, 0x11, 0x20, 0x82, 0x11, 0x05, | 15 0xf8, 0x00, 0x00, 0x11, 0x20, 0x82, 0x11, 0x05, |
16 0x05, 0x0a, | 16 0x05, 0x0a, |
17 // user data: | 17 // user data: |
18 0x6a, 0xc8, 0xb2, 0xbc, 0x7c, 0x9a, 0x83, 0xc2, | 18 0x6a, 0xc8, 0xb2, 0xbc, 0x7c, 0x9a, 0x83, 0xc2, |
19 0x20, 0xf6, 0xdb, 0x7d, 0x2e, 0xcb, 0x41, 0xed, | 19 0x20, 0xf6, 0xdb, 0x7d, 0x2e, 0xcb, 0x41, 0xed, |
20 0xf2, 0x7c, 0x1e, 0x3e, 0x97, 0x41, 0x1b, 0xde, | 20 0xf2, 0x7c, 0x1e, 0x3e, 0x97, 0x41, 0x1b, 0xde, |
21 0x06, 0x75, 0x4f, 0xd3, 0xd1, 0xa0, 0xf9, 0xbb, | 21 0x06, 0x75, 0x4f, 0xd3, 0xd1, 0xa0, 0xf9, 0xbb, |
22 0x5d, 0x06, 0x95, 0xf1, 0xf4, 0xb2, 0x9b, 0x5c, | 22 0x5d, 0x06, 0x95, 0xf1, 0xf4, 0xb2, 0x9b, 0x5c, |
23 0x26, 0x83, 0xc6, 0xe8, 0xb0, 0x3c, 0x3c, 0xa6, | 23 0x26, 0x83, 0xc6, 0xe8, 0xb0, 0x3c, 0x3c, 0xa6, |
24 0x97, 0xe5, 0xf3, 0x4d, 0x6a, 0xe3, 0x03, 0xd1, | 24 0x97, 0xe5, 0xf3, 0x4d, 0x6a, 0xe3, 0x03, 0xd1, |
25 0xd1, 0xf2, 0xf7, 0xdd, 0x0d, 0x4a, 0xbb, 0x59, | 25 0xd1, 0xf2, 0xf7, 0xdd, 0x0d, 0x4a, 0xbb, 0x59, |
26 0xa0, 0x79, 0x7d, 0x8c, 0x06, 0x85, 0xe7, 0xa0, | 26 0xa0, 0x79, 0x7d, 0x8c, 0x06, 0x85, 0xe7, 0xa0, |
27 0x00, 0x28, 0xec, 0x26, 0x83, 0x2a, 0x96, 0x0b, | 27 0x00, 0x28, 0xec, 0x26, 0x83, 0x2a, 0x96, 0x0b, |
28 0x28, 0xec, 0x26, 0x83, 0xbe, 0x60, 0x50, 0x78, | 28 0x28, 0xec, 0x26, 0x83, 0xbe, 0x60, 0x50, 0x78, |
29 0x0e, 0xba, 0x97, 0xd9, 0x6c, 0x17 | 29 0x0e, 0xba, 0x97, 0xd9, 0x6c, 0x17 |
30 }; | 30 }; |
31 | 31 |
| 32 const uint8_t pdu2[] = { |
| 33 0x07, 0x91, 0x97, 0x30, 0x07, 0x11, 0x11, 0xf1, |
| 34 0x04, 0x14, 0xd0, 0x49, 0x37, 0xbd, 0x2c, 0x77, |
| 35 0x97, 0xe9, 0xd3, 0xe6, 0x14, 0x00, 0x08, 0x11, |
| 36 0x30, 0x92, 0x91, 0x02, 0x40, 0x61, 0x08, 0x04, |
| 37 0x42, 0x04, 0x35, 0x04, 0x41, 0x04, 0x42 |
| 38 }; |
| 39 |
32 TEST(SmsMessage, CreateFromPdu) { | 40 TEST(SmsMessage, CreateFromPdu) { |
33 SmsMessage* sms = SmsMessage::CreateMessage(pdu, sizeof(pdu)); | 41 SmsMessage* sms = SmsMessage::CreateMessage(pdu1, sizeof(pdu1)); |
34 | 42 |
35 ASSERT_TRUE(NULL != sms); | 43 ASSERT_TRUE(NULL != sms); |
36 EXPECT_EQ("12404492164", sms->smsc_address()); | 44 EXPECT_EQ("12404492164", sms->smsc_address()); |
37 EXPECT_EQ("16175927198", sms->sender_address()); | 45 EXPECT_EQ("16175927198", sms->sender_address()); |
38 EXPECT_EQ("110228115050-08", sms->timestamp()); | 46 EXPECT_EQ("110228115050-08", sms->timestamp()); |
39 EXPECT_EQ("Here's a longer message [{with some extended characters}] " | 47 EXPECT_EQ("Here's a longer message [{with some extended characters}] " |
40 "thrown in, such as £ and ΩΠΨ and §¿ as well.", sms->text()); | 48 "thrown in, such as £ and ΩΠΨ and §¿ as well.", sms->text()); |
41 } | 49 } |
42 | 50 |
| 51 TEST(SmsMessage, CreateFromPduWithAlphaSenderAndUcs2Text) { |
| 52 SmsMessage* sms = SmsMessage::CreateMessage(pdu2, sizeof(pdu2)); |
| 53 |
| 54 ASSERT_TRUE(NULL != sms); |
| 55 EXPECT_EQ("79037011111", sms->smsc_address()); |
| 56 EXPECT_EQ("InternetSMS", sms->sender_address()); |
| 57 EXPECT_EQ("110329192004+05", sms->timestamp()); |
| 58 EXPECT_EQ("тест", sms->text()); |
| 59 } |
| 60 |
43 int main(int argc, char* argv[]) { | 61 int main(int argc, char* argv[]) { |
44 testing::InitGoogleTest(&argc, argv); | 62 testing::InitGoogleTest(&argc, argv); |
45 google::InitGoogleLogging(argv[0]); | 63 google::InitGoogleLogging(argv[0]); |
46 google::ParseCommandLineFlags(&argc, &argv, true); | 64 google::ParseCommandLineFlags(&argc, &argv, true); |
47 | 65 |
48 return RUN_ALL_TESTS(); | 66 return RUN_ALL_TESTS(); |
49 } | 67 } |
OLD | NEW |