|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Tests for AppInstaller class |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "appinstaller.h" |
|
19 |
|
20 #include "TestHarness.h" |
|
21 #include "logger.h" |
|
22 #include "commsmessage.h" |
|
23 |
|
24 |
|
25 using namespace std; |
|
26 using namespace java::debug; |
|
27 using namespace java::comms; |
|
28 using java::util::Uid; |
|
29 |
|
30 class TestAppInstaller : public AppInstaller |
|
31 { |
|
32 public: |
|
33 TestAppInstaller(const std::wstring& aFilename) : AppInstaller(aFilename), |
|
34 nextOperationCount(0), handleOperationCount(0) {}; |
|
35 virtual ~TestAppInstaller() {}; |
|
36 |
|
37 virtual CommsMessage getNextOperation() |
|
38 { |
|
39 nextOperationCount++; |
|
40 return AppInstaller::getNextOperation(); |
|
41 }; |
|
42 |
|
43 virtual void handleOperationResult(CommsMessage& aMessage) |
|
44 { |
|
45 handleOperationCount++; |
|
46 AppInstaller::handleOperationResult(aMessage); |
|
47 }; |
|
48 |
|
49 int nextOperationCount; |
|
50 int handleOperationCount; |
|
51 }; |
|
52 |
|
53 |
|
54 TEST_GROUP(TestAppInstaller) |
|
55 { |
|
56 TEST_SETUP() |
|
57 { |
|
58 } |
|
59 |
|
60 TEST_TEARDOWN() |
|
61 { |
|
62 } |
|
63 }; |
|
64 |
|
65 |
|
66 TEST(TestAppInstaller, install) |
|
67 { |
|
68 TestAppInstaller installer(L"dummy.jar"); |
|
69 |
|
70 int rc = installer.install(); |
|
71 CHECK(rc != 0); |
|
72 CHECK(installer.nextOperationCount == 2); |
|
73 CHECK(installer.handleOperationCount == 2); |
|
74 } |
|
75 |
|
76 TEST(TestAppInstaller, getNextOperation) |
|
77 { |
|
78 wstring dummy(L"dummy.jar"); |
|
79 TestAppInstaller installer(dummy); |
|
80 |
|
81 CommsMessage msg = installer.getNextOperation(); |
|
82 int operation = -1; |
|
83 wstring filename; |
|
84 |
|
85 msg >> operation >> filename; |
|
86 CHECK(operation == INSTALL_OPERATION); |
|
87 CHECK(filename.compare(dummy) == 0); |
|
88 |
|
89 // install is not done yet so next operation must be still INSTALL |
|
90 msg = installer.getNextOperation(); |
|
91 msg >> operation >> filename; |
|
92 CHECK(operation == INSTALL_OPERATION); |
|
93 CHECK(filename.compare(dummy) == 0); |
|
94 |
|
95 CommsMessage result; |
|
96 Uid appUid(L"[10000001]"); |
|
97 Uid suiteUid(L"[30000003]"); |
|
98 result << INSTALL_OPERATION << 0 << 1 << appUid << suiteUid; |
|
99 installer.handleOperationResult(result); |
|
100 |
|
101 msg = installer.getNextOperation(); |
|
102 msg >> operation; |
|
103 CHECK(operation == EXIT_OPERATION); |
|
104 } |
|
105 |
|
106 TEST(TestAppInstaller, handleOperationResult) |
|
107 { |
|
108 CommsMessage msg; |
|
109 Uid appUid1(L"[10000001]"); |
|
110 Uid appUid2(L"[20000002]"); |
|
111 Uid suiteUid(L"[30000003]"); |
|
112 |
|
113 msg << INSTALL_OPERATION << 0 << 2 << appUid1 << appUid2 << suiteUid; |
|
114 |
|
115 TestAppInstaller installer(L"dummy.jar"); |
|
116 installer.handleOperationResult(msg); |
|
117 std::list<Uid> appUids = installer.getAppUids(); |
|
118 |
|
119 CHECK(suiteUid == installer.getSuiteUid()); |
|
120 CHECK(appUids.size() == 2); |
|
121 CHECK(appUids.front() == appUid1); |
|
122 CHECK(appUids.back() == appUid2); |
|
123 } |
|
124 |