blob: 3d0ff51efd08af25736baeb8f58f676640b5f7c6 [file] [log] [blame]
hashimoto@chromium.org5fdbcf72012-06-05 13:15:50 +09001// Copyright (c) 2012 The Chromium 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 "dbus/string_util.h"
6#include "testing/gtest/include/gtest/gtest.h"
7
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +09008namespace dbus {
9
hashimoto@chromium.org5fdbcf72012-06-05 13:15:50 +090010TEST(StringUtilTest, IsValidObjectPath) {
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +090011 EXPECT_TRUE(IsValidObjectPath("/"));
12 EXPECT_TRUE(IsValidObjectPath("/foo/bar"));
13 EXPECT_TRUE(IsValidObjectPath("/hoge_fuga/piyo123"));
hashimoto@chromium.org5fdbcf72012-06-05 13:15:50 +090014 // Empty string.
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +090015 EXPECT_FALSE(IsValidObjectPath(std::string()));
16 // Empty element.
17 EXPECT_FALSE(IsValidObjectPath("//"));
18 EXPECT_FALSE(IsValidObjectPath("/foo//bar"));
19 EXPECT_FALSE(IsValidObjectPath("/foo///bar"));
hashimoto@chromium.org5fdbcf72012-06-05 13:15:50 +090020 // Trailing '/'.
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +090021 EXPECT_FALSE(IsValidObjectPath("/foo/"));
22 EXPECT_FALSE(IsValidObjectPath("/foo/bar/"));
hashimoto@chromium.org5fdbcf72012-06-05 13:15:50 +090023 // Not beginning with '/'.
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +090024 EXPECT_FALSE(IsValidObjectPath("foo/bar"));
hashimoto@chromium.org5fdbcf72012-06-05 13:15:50 +090025 // Invalid characters.
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +090026 EXPECT_FALSE(IsValidObjectPath("/foo.bar"));
27 EXPECT_FALSE(IsValidObjectPath("/foo/*"));
28 EXPECT_FALSE(IsValidObjectPath("/foo/bar(1)"));
hashimoto@chromium.org5fdbcf72012-06-05 13:15:50 +090029}
thestig@chromium.orgf0b7eac2013-06-13 15:37:19 +090030
31} // namespace dbus