blob: 1a0b19113370864049b9c1dc6fd7d5d0cdc974dc [file] [log] [blame]
Jed Estepb8a693b2016-03-09 17:51:34 -08001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agree to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <fcntl.h>
18#include <gtest/gtest.h>
19#include <stdio.h>
20#include <stdlib.h>
21#include <sys/stat.h>
22#include <sys/statvfs.h>
23#include <sys/types.h>
24#include <time.h>
25
Tao Baofada91c2016-10-27 18:16:06 -070026#include <memory>
Jed Estepb8a693b2016-03-09 17:51:34 -080027#include <string>
Tao Baofada91c2016-10-27 18:16:06 -070028#include <vector>
Jed Estepb8a693b2016-03-09 17:51:34 -080029
30#include <android-base/file.h>
31#include <android-base/stringprintf.h>
32#include <android-base/test_utils.h>
Tao Baofada91c2016-10-27 18:16:06 -070033#include <openssl/sha.h>
Jed Estepb8a693b2016-03-09 17:51:34 -080034
35#include "applypatch/applypatch.h"
Tao Bao36c35112016-10-25 14:17:26 -070036#include "applypatch/applypatch_modes.h"
Jed Estepb8a693b2016-03-09 17:51:34 -080037#include "common/test_constants.h"
Jed Estepb8a693b2016-03-09 17:51:34 -080038#include "print_sha1.h"
39
Tao Bao36c35112016-10-25 14:17:26 -070040static void sha1sum(const std::string& fname, std::string* sha1, size_t* fsize = nullptr) {
41 ASSERT_NE(nullptr, sha1);
Tao Baofada91c2016-10-27 18:16:06 -070042
Tao Bao36c35112016-10-25 14:17:26 -070043 std::string data;
44 ASSERT_TRUE(android::base::ReadFileToString(fname, &data));
Jed Estepb8a693b2016-03-09 17:51:34 -080045
Tao Bao36c35112016-10-25 14:17:26 -070046 if (fsize != nullptr) {
47 *fsize = data.size();
48 }
49
50 uint8_t digest[SHA_DIGEST_LENGTH];
51 SHA1(reinterpret_cast<const uint8_t*>(data.c_str()), data.size(), digest);
52 *sha1 = print_sha1(digest);
Jed Estepb8a693b2016-03-09 17:51:34 -080053}
54
55static void mangle_file(const std::string& fname) {
Tao Bao36c35112016-10-25 14:17:26 -070056 std::string content;
57 content.reserve(1024);
58 for (size_t i = 0; i < 1024; i++) {
59 content[i] = rand() % 256;
60 }
61 ASSERT_TRUE(android::base::WriteStringToFile(content, fname));
Jed Estepb8a693b2016-03-09 17:51:34 -080062}
63
Tao Baofada91c2016-10-27 18:16:06 -070064static bool file_cmp(const std::string& f1, const std::string& f2) {
Tao Bao36c35112016-10-25 14:17:26 -070065 std::string c1;
66 android::base::ReadFileToString(f1, &c1);
67 std::string c2;
68 android::base::ReadFileToString(f2, &c2);
69 return c1 == c2;
Jed Estepb8a693b2016-03-09 17:51:34 -080070}
71
Jed Estepb8a693b2016-03-09 17:51:34 -080072class ApplyPatchTest : public ::testing::Test {
Tao Bao36c35112016-10-25 14:17:26 -070073 public:
74 static void SetUpTestCase() {
75 // set up files
76 old_file = from_testdata_base("old.file");
77 new_file = from_testdata_base("new.file");
78 patch_file = from_testdata_base("patch.bsdiff");
79 rand_file = "/cache/applypatch_test_rand.file";
80 cache_file = "/cache/saved.file";
Jed Estepb8a693b2016-03-09 17:51:34 -080081
Tao Bao36c35112016-10-25 14:17:26 -070082 // write stuff to rand_file
83 ASSERT_TRUE(android::base::WriteStringToFile("hello", rand_file));
Jed Estepb8a693b2016-03-09 17:51:34 -080084
Tao Bao36c35112016-10-25 14:17:26 -070085 // set up SHA constants
86 sha1sum(old_file, &old_sha1);
87 sha1sum(new_file, &new_sha1);
88 srand(time(nullptr));
89 bad_sha1_a = android::base::StringPrintf("%040x", rand());
90 bad_sha1_b = android::base::StringPrintf("%040x", rand());
Jed Estepb8a693b2016-03-09 17:51:34 -080091
Tao Bao36c35112016-10-25 14:17:26 -070092 struct stat st;
93 stat(&new_file[0], &st);
94 new_size = st.st_size;
95 }
Jed Estepb8a693b2016-03-09 17:51:34 -080096
Tao Bao36c35112016-10-25 14:17:26 -070097 static std::string old_file;
98 static std::string new_file;
99 static std::string rand_file;
100 static std::string cache_file;
101 static std::string patch_file;
Jed Estepb8a693b2016-03-09 17:51:34 -0800102
Tao Bao36c35112016-10-25 14:17:26 -0700103 static std::string old_sha1;
104 static std::string new_sha1;
105 static std::string bad_sha1_a;
106 static std::string bad_sha1_b;
Jed Estepb8a693b2016-03-09 17:51:34 -0800107
Tao Bao36c35112016-10-25 14:17:26 -0700108 static size_t new_size;
Jed Estepb8a693b2016-03-09 17:51:34 -0800109};
110
111std::string ApplyPatchTest::old_file;
112std::string ApplyPatchTest::new_file;
113
Tao Baofada91c2016-10-27 18:16:06 -0700114static void cp(const std::string& src, const std::string& tgt) {
Tao Bao36c35112016-10-25 14:17:26 -0700115 std::string cmd = "cp " + src + " " + tgt;
116 system(cmd.c_str());
Jed Estepb8a693b2016-03-09 17:51:34 -0800117}
118
119static void backup_old() {
Tao Bao36c35112016-10-25 14:17:26 -0700120 cp(ApplyPatchTest::old_file, ApplyPatchTest::cache_file);
Jed Estepb8a693b2016-03-09 17:51:34 -0800121}
122
123static void restore_old() {
Tao Bao36c35112016-10-25 14:17:26 -0700124 cp(ApplyPatchTest::cache_file, ApplyPatchTest::old_file);
Jed Estepb8a693b2016-03-09 17:51:34 -0800125}
126
127class ApplyPatchCacheTest : public ApplyPatchTest {
Tao Bao36c35112016-10-25 14:17:26 -0700128 public:
129 virtual void SetUp() {
130 backup_old();
131 }
Jed Estepb8a693b2016-03-09 17:51:34 -0800132
Tao Bao36c35112016-10-25 14:17:26 -0700133 virtual void TearDown() {
134 restore_old();
135 }
Jed Estepb8a693b2016-03-09 17:51:34 -0800136};
137
138class ApplyPatchFullTest : public ApplyPatchCacheTest {
Tao Bao36c35112016-10-25 14:17:26 -0700139 public:
140 static void SetUpTestCase() {
141 ApplyPatchTest::SetUpTestCase();
Jed Estepb8a693b2016-03-09 17:51:34 -0800142
Tao Bao36c35112016-10-25 14:17:26 -0700143 output_f = new TemporaryFile();
144 output_loc = std::string(output_f->path);
Jed Estepb8a693b2016-03-09 17:51:34 -0800145
Tao Bao36c35112016-10-25 14:17:26 -0700146 struct FileContents fc;
Jed Estepb8a693b2016-03-09 17:51:34 -0800147
Tao Bao36c35112016-10-25 14:17:26 -0700148 ASSERT_EQ(0, LoadFileContents(&rand_file[0], &fc));
149 patches.push_back(
150 std::make_unique<Value>(VAL_BLOB, std::string(fc.data.begin(), fc.data.end())));
Jed Estepb8a693b2016-03-09 17:51:34 -0800151
Tao Bao36c35112016-10-25 14:17:26 -0700152 ASSERT_EQ(0, LoadFileContents(&patch_file[0], &fc));
153 patches.push_back(
154 std::make_unique<Value>(VAL_BLOB, std::string(fc.data.begin(), fc.data.end())));
155 }
Tao Baofada91c2016-10-27 18:16:06 -0700156
Tao Bao36c35112016-10-25 14:17:26 -0700157 static void TearDownTestCase() {
158 delete output_f;
159 patches.clear();
160 }
Tao Baofada91c2016-10-27 18:16:06 -0700161
Tao Bao36c35112016-10-25 14:17:26 -0700162 static std::vector<std::unique_ptr<Value>> patches;
163 static TemporaryFile* output_f;
164 static std::string output_loc;
Jed Estepb8a693b2016-03-09 17:51:34 -0800165};
166
167class ApplyPatchDoubleCacheTest : public ApplyPatchFullTest {
Tao Bao36c35112016-10-25 14:17:26 -0700168 public:
169 virtual void SetUp() {
170 ApplyPatchCacheTest::SetUp();
171 cp(cache_file, "/cache/reallysaved.file");
172 }
Jed Estepb8a693b2016-03-09 17:51:34 -0800173
Tao Bao36c35112016-10-25 14:17:26 -0700174 virtual void TearDown() {
175 cp("/cache/reallysaved.file", cache_file);
176 ApplyPatchCacheTest::TearDown();
177 }
Jed Estepb8a693b2016-03-09 17:51:34 -0800178};
179
180std::string ApplyPatchTest::rand_file;
181std::string ApplyPatchTest::patch_file;
182std::string ApplyPatchTest::cache_file;
183std::string ApplyPatchTest::old_sha1;
184std::string ApplyPatchTest::new_sha1;
185std::string ApplyPatchTest::bad_sha1_a;
186std::string ApplyPatchTest::bad_sha1_b;
187
188size_t ApplyPatchTest::new_size;
189
Tao Baofada91c2016-10-27 18:16:06 -0700190std::vector<std::unique_ptr<Value>> ApplyPatchFullTest::patches;
Jed Estepb8a693b2016-03-09 17:51:34 -0800191TemporaryFile* ApplyPatchFullTest::output_f;
192std::string ApplyPatchFullTest::output_loc;
193
Tianjie Xua5fd5ab2016-10-18 15:18:22 -0700194TEST_F(ApplyPatchTest, CheckModeSkip) {
Tao Bao36c35112016-10-25 14:17:26 -0700195 std::vector<std::string> sha1s;
196 ASSERT_EQ(0, applypatch_check(&old_file[0], sha1s));
Tianjie Xua5fd5ab2016-10-18 15:18:22 -0700197}
198
Jed Estepb8a693b2016-03-09 17:51:34 -0800199TEST_F(ApplyPatchTest, CheckModeSingle) {
Tao Bao36c35112016-10-25 14:17:26 -0700200 std::vector<std::string> sha1s = { old_sha1 };
201 ASSERT_EQ(0, applypatch_check(&old_file[0], sha1s));
Jed Estepb8a693b2016-03-09 17:51:34 -0800202}
203
204TEST_F(ApplyPatchTest, CheckModeMultiple) {
Tao Bao36c35112016-10-25 14:17:26 -0700205 std::vector<std::string> sha1s = { bad_sha1_a, old_sha1, bad_sha1_b };
206 ASSERT_EQ(0, applypatch_check(&old_file[0], sha1s));
Jed Estepb8a693b2016-03-09 17:51:34 -0800207}
208
209TEST_F(ApplyPatchTest, CheckModeFailure) {
Tao Bao36c35112016-10-25 14:17:26 -0700210 std::vector<std::string> sha1s = { bad_sha1_a, bad_sha1_b };
211 ASSERT_NE(0, applypatch_check(&old_file[0], sha1s));
Jed Estepb8a693b2016-03-09 17:51:34 -0800212}
213
214TEST_F(ApplyPatchCacheTest, CheckCacheCorruptedSingle) {
Tao Bao36c35112016-10-25 14:17:26 -0700215 mangle_file(old_file);
216 std::vector<std::string> sha1s = { old_sha1 };
217 ASSERT_EQ(0, applypatch_check(&old_file[0], sha1s));
Jed Estepb8a693b2016-03-09 17:51:34 -0800218}
219
220TEST_F(ApplyPatchCacheTest, CheckCacheCorruptedMultiple) {
Tao Bao36c35112016-10-25 14:17:26 -0700221 mangle_file(old_file);
222 std::vector<std::string> sha1s = { bad_sha1_a, old_sha1, bad_sha1_b };
223 ASSERT_EQ(0, applypatch_check(&old_file[0], sha1s));
Jed Estepb8a693b2016-03-09 17:51:34 -0800224}
225
226TEST_F(ApplyPatchCacheTest, CheckCacheCorruptedFailure) {
Tao Bao36c35112016-10-25 14:17:26 -0700227 mangle_file(old_file);
228 std::vector<std::string> sha1s = { bad_sha1_a, bad_sha1_b };
229 ASSERT_NE(0, applypatch_check(&old_file[0], sha1s));
Jed Estepb8a693b2016-03-09 17:51:34 -0800230}
231
232TEST_F(ApplyPatchCacheTest, CheckCacheMissingSingle) {
Tao Bao36c35112016-10-25 14:17:26 -0700233 unlink(&old_file[0]);
234 std::vector<std::string> sha1s = { old_sha1 };
235 ASSERT_EQ(0, applypatch_check(&old_file[0], sha1s));
Jed Estepb8a693b2016-03-09 17:51:34 -0800236}
237
238TEST_F(ApplyPatchCacheTest, CheckCacheMissingMultiple) {
Tao Bao36c35112016-10-25 14:17:26 -0700239 unlink(&old_file[0]);
240 std::vector<std::string> sha1s = { bad_sha1_a, old_sha1, bad_sha1_b };
241 ASSERT_EQ(0, applypatch_check(&old_file[0], sha1s));
Jed Estepb8a693b2016-03-09 17:51:34 -0800242}
243
244TEST_F(ApplyPatchCacheTest, CheckCacheMissingFailure) {
Tao Bao36c35112016-10-25 14:17:26 -0700245 unlink(&old_file[0]);
246 std::vector<std::string> sha1s = { bad_sha1_a, bad_sha1_b };
247 ASSERT_NE(0, applypatch_check(&old_file[0], sha1s));
Jed Estepb8a693b2016-03-09 17:51:34 -0800248}
249
250TEST_F(ApplyPatchFullTest, ApplyInPlace) {
Tao Bao36c35112016-10-25 14:17:26 -0700251 std::vector<std::string> sha1s = { bad_sha1_a, old_sha1 };
252 ASSERT_EQ(0, applypatch(&old_file[0], "-", &new_sha1[0], new_size, sha1s, patches, nullptr));
253 ASSERT_TRUE(file_cmp(old_file, new_file));
254
255 // reapply, applypatch is idempotent so it should succeed
256 ASSERT_EQ(0, applypatch(&old_file[0], "-", &new_sha1[0], new_size, sha1s, patches, nullptr));
257 ASSERT_TRUE(file_cmp(old_file, new_file));
Jed Estepb8a693b2016-03-09 17:51:34 -0800258}
259
260TEST_F(ApplyPatchFullTest, ApplyInNewLocation) {
Tao Bao36c35112016-10-25 14:17:26 -0700261 std::vector<std::string> sha1s = { bad_sha1_a, old_sha1 };
262 // Apply bsdiff patch to new location.
263 ASSERT_EQ(
264 0, applypatch(&old_file[0], &output_loc[0], &new_sha1[0], new_size, sha1s, patches, nullptr));
265 ASSERT_TRUE(file_cmp(output_loc, new_file));
Tao Baofada91c2016-10-27 18:16:06 -0700266
Tao Bao36c35112016-10-25 14:17:26 -0700267 // Reapply to the same location.
268 ASSERT_EQ(
269 0, applypatch(&old_file[0], &output_loc[0], &new_sha1[0], new_size, sha1s, patches, nullptr));
270 ASSERT_TRUE(file_cmp(output_loc, new_file));
Jed Estepb8a693b2016-03-09 17:51:34 -0800271}
272
273TEST_F(ApplyPatchFullTest, ApplyCorruptedInNewLocation) {
Tao Bao36c35112016-10-25 14:17:26 -0700274 std::vector<std::string> sha1s = { bad_sha1_a, old_sha1 };
275 // Apply bsdiff patch to new location with corrupted source.
276 mangle_file(old_file);
277 ASSERT_EQ(
278 0, applypatch(&old_file[0], &output_loc[0], &new_sha1[0], new_size, sha1s, patches, nullptr));
279 ASSERT_TRUE(file_cmp(output_loc, new_file));
Tao Baofada91c2016-10-27 18:16:06 -0700280
Tao Bao36c35112016-10-25 14:17:26 -0700281 // Reapply bsdiff patch to new location with corrupted source.
282 ASSERT_EQ(
283 0, applypatch(&old_file[0], &output_loc[0], &new_sha1[0], new_size, sha1s, patches, nullptr));
284 ASSERT_TRUE(file_cmp(output_loc, new_file));
Jed Estepb8a693b2016-03-09 17:51:34 -0800285}
286
287TEST_F(ApplyPatchDoubleCacheTest, ApplyDoubleCorruptedInNewLocation) {
Tao Bao36c35112016-10-25 14:17:26 -0700288 std::vector<std::string> sha1s = { bad_sha1_a, old_sha1 };
Tao Baofada91c2016-10-27 18:16:06 -0700289
Tao Bao36c35112016-10-25 14:17:26 -0700290 // Apply bsdiff patch to new location with corrupted source and copy (no new file).
291 // Expected to fail.
292 mangle_file(old_file);
293 mangle_file(cache_file);
294 ASSERT_NE(
295 0, applypatch(&old_file[0], &output_loc[0], &new_sha1[0], new_size, sha1s, patches, nullptr));
296 ASSERT_FALSE(file_cmp(output_loc, new_file));
Tao Baofada91c2016-10-27 18:16:06 -0700297
Tao Bao36c35112016-10-25 14:17:26 -0700298 // Expected to fail again on retry.
299 ASSERT_NE(
300 0, applypatch(&old_file[0], &output_loc[0], &new_sha1[0], new_size, sha1s, patches, nullptr));
301 ASSERT_FALSE(file_cmp(output_loc, new_file));
Tao Baofada91c2016-10-27 18:16:06 -0700302
Tao Bao36c35112016-10-25 14:17:26 -0700303 // Expected to fail with incorrect new file.
304 mangle_file(output_loc);
305 ASSERT_NE(
306 0, applypatch(&old_file[0], &output_loc[0], &new_sha1[0], new_size, sha1s, patches, nullptr));
307 ASSERT_FALSE(file_cmp(output_loc, new_file));
308}
309
310TEST(ApplyPatchModes, InvalidArgs) {
311 // At least two args (including the filename).
312 ASSERT_EQ(2, applypatch_modes(1, (const char* []){ "applypatch" }));
313
314 // Unrecognized args.
315 ASSERT_EQ(2, applypatch_modes(2, (const char* []){ "applypatch", "-x" }));
316}
317
318TEST(ApplyPatchModes, PatchMode) {
319 std::string boot_img = from_testdata_base("boot.img");
320 size_t boot_img_size;
321 std::string boot_img_sha1;
322 sha1sum(boot_img, &boot_img_sha1, &boot_img_size);
323
324 std::string recovery_img = from_testdata_base("recovery.img");
325 size_t recovery_img_size;
326 std::string recovery_img_sha1;
327 sha1sum(recovery_img, &recovery_img_sha1, &recovery_img_size);
328
329 std::string bonus_file = from_testdata_base("bonus.file");
330
331 // applypatch -b <bonus-file> <src-file> <tgt-file> <tgt-sha1> <tgt-size> <src-sha1>:<patch>
332 TemporaryFile tmp1;
333 std::vector<const char*> args = {
334 "applypatch",
335 "-b",
336 bonus_file.c_str(),
337 boot_img.c_str(),
338 tmp1.path,
339 recovery_img_sha1.c_str(),
340 std::to_string(recovery_img_size).c_str(),
341 (boot_img_sha1 + ":" + from_testdata_base("recovery-from-boot.p")).c_str()
342 };
343 ASSERT_EQ(0, applypatch_modes(args.size(), args.data()));
344
345 // applypatch <src-file> <tgt-file> <tgt-sha1> <tgt-size> <src-sha1>:<patch>
346 TemporaryFile tmp2;
347 std::vector<const char*> args2 = {
348 "applypatch",
349 boot_img.c_str(),
350 tmp2.path,
351 recovery_img_sha1.c_str(),
352 std::to_string(recovery_img_size).c_str(),
353 (boot_img_sha1 + ":" + from_testdata_base("recovery-from-boot-with-bonus.p")).c_str()
354 };
355 ASSERT_EQ(0, applypatch_modes(args2.size(), args2.data()));
356
357 // applypatch -b <bonus-file> <src-file> <tgt-file> <tgt-sha1> <tgt-size> \
358 // <src-sha1-fake>:<patch1> <src-sha1>:<patch2>
359 TemporaryFile tmp3;
360 std::string bad_sha1_a = android::base::StringPrintf("%040x", rand());
361 std::string bad_sha1_b = android::base::StringPrintf("%040x", rand());
362 std::vector<const char*> args3 = {
363 "applypatch",
364 "-b",
365 bonus_file.c_str(),
366 boot_img.c_str(),
367 tmp3.path,
368 recovery_img_sha1.c_str(),
369 std::to_string(recovery_img_size).c_str(),
370 (bad_sha1_a + ":" + from_testdata_base("recovery-from-boot.p")).c_str(),
371 (boot_img_sha1 + ":" + from_testdata_base("recovery-from-boot.p")).c_str(),
372 (bad_sha1_b + ":" + from_testdata_base("recovery-from-boot.p")).c_str(),
373 };
374 ASSERT_EQ(0, applypatch_modes(args3.size(), args3.data()));
375}
376
377TEST(ApplyPatchModes, PatchModeInvalidArgs) {
378 // Invalid bonus file.
379 ASSERT_NE(0, applypatch_modes(3, (const char* []){ "applypatch", "-b", "/doesntexist" }));
380
381 std::string bonus_file = from_testdata_base("bonus.file");
382 // With bonus file, but missing args.
383 ASSERT_EQ(2, applypatch_modes(3, (const char* []){ "applypatch", "-b", bonus_file.c_str() }));
384
385 std::string boot_img = from_testdata_base("boot.img");
386 size_t boot_img_size;
387 std::string boot_img_sha1;
388 sha1sum(boot_img, &boot_img_sha1, &boot_img_size);
389
390 std::string recovery_img = from_testdata_base("recovery.img");
391 size_t recovery_img_size;
392 std::string recovery_img_sha1;
393 sha1sum(recovery_img, &recovery_img_sha1, &recovery_img_size);
394
395 // Bonus file is not supported in flash mode.
396 // applypatch -b <bonus-file> <src-file> <tgt-file> <tgt-sha1> <tgt-size>
397 TemporaryFile tmp4;
398 std::vector<const char*> args4 = {
399 "applypatch",
400 "-b",
401 bonus_file.c_str(),
402 boot_img.c_str(),
403 tmp4.path,
404 recovery_img_sha1.c_str(),
405 std::to_string(recovery_img_size).c_str() };
406 ASSERT_NE(0, applypatch_modes(args4.size(), args4.data()));
407
408 // Failed to parse patch args.
409 TemporaryFile tmp5;
410 std::vector<const char*> args5 = {
411 "applypatch",
412 boot_img.c_str(),
413 tmp5.path,
414 recovery_img_sha1.c_str(),
415 std::to_string(recovery_img_size).c_str(),
416 ("invalid-sha1:filename" + from_testdata_base("recovery-from-boot-with-bonus.p")).c_str(),
417 };
418 ASSERT_NE(0, applypatch_modes(args5.size(), args5.data()));
419
420 // Target size cannot be zero.
421 TemporaryFile tmp6;
422 std::vector<const char*> args6 = {
423 "applypatch",
424 boot_img.c_str(),
425 tmp6.path,
426 recovery_img_sha1.c_str(),
427 "0", // target size
428 (boot_img_sha1 + ":" + from_testdata_base("recovery-from-boot-with-bonus.p")).c_str()
429 };
430 ASSERT_NE(0, applypatch_modes(args6.size(), args6.data()));
431}
432
433TEST(ApplyPatchModes, CheckModeInvalidArgs) {
434 // Insufficient args.
435 ASSERT_EQ(2, applypatch_modes(2, (const char* []){ "applypatch", "-c" }));
436}
437
438TEST(ApplyPatchModes, SpaceModeInvalidArgs) {
439 // Insufficient args.
440 ASSERT_EQ(2, applypatch_modes(2, (const char* []){ "applypatch", "-s" }));
441
442 // Invalid bytes arg.
443 ASSERT_EQ(1, applypatch_modes(3, (const char* []){ "applypatch", "-s", "x" }));
444
445 // 0 is invalid.
446 ASSERT_EQ(1, applypatch_modes(3, (const char* []){ "applypatch", "-s", "0" }));
447
448 // 0x10 is fine.
449 ASSERT_EQ(0, applypatch_modes(3, (const char* []){ "applypatch", "-s", "0x10" }));
450}
451
452TEST(ApplyPatchModes, ShowLicenses) {
453 ASSERT_EQ(0, applypatch_modes(2, (const char* []){ "applypatch", "-l" }));
Jed Estepb8a693b2016-03-09 17:51:34 -0800454}