blob: 6f8902e04b85d97df0736542eb1bf15dd5ae6d36 [file] [log] [blame]
Lei Zhang0d66f922012-08-07 15:22:05 -07001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "mtpd/device_manager.h"
6
7#include <string>
8#include <vector>
9
10#include <gtest/gtest.h>
11
12namespace mtpd {
13namespace {
14
15TEST(DeviceManagerTest, ParseStorageName) {
16 struct ParseStorageNameTestCase {
17 const char* input;
18 bool expected_result;
19 const char* expected_bus;
20 uint32_t expected_storage_id;
21 } test_cases[] = {
22 { "usb:123:4", true, "usb:123", 4 },
23 { "usb:1,2,3:4", true, "usb:1,2,3", 4 },
24 { "notusb:123:4", false, "", 0 },
25 { "usb:123:4:badfield", false, "", 0 },
26 { "usb:123:not_number", false, "", 0 },
27 };
28
29 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) {
30 std::string bus;
31 uint32_t storage_id = static_cast<uint32_t>(-1);
32 bool result =
33 DeviceManager::ParseStorageName(test_cases[i].input, &bus, &storage_id);
34 EXPECT_EQ(test_cases[i].expected_result, result);
35 if (test_cases[i].expected_result) {
36 EXPECT_EQ(test_cases[i].expected_bus, bus);
37 EXPECT_EQ(test_cases[i].expected_storage_id, storage_id);
38 }
39 }
40}
41
42} // namespace
43} // namespace mtp