blob: cedd2691b11877d317c6412e8e12d09fe479e235 [file] [log] [blame]
Alex Deymo38429cf2015-11-11 18:27:22 -08001//
2// Copyright (C) 2015 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 agreed 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 "update_engine/metrics_utils.h"
18
19#include <gtest/gtest.h>
20
Alex Deymoa2591792015-11-17 00:39:40 -030021#include "update_engine/common/fake_clock.h"
22#include "update_engine/common/fake_prefs.h"
Alex Deymoa2591792015-11-17 00:39:40 -030023
Alex Deymo38429cf2015-11-11 18:27:22 -080024namespace chromeos_update_engine {
25namespace metrics_utils {
26
27class MetricsUtilsTest : public ::testing::Test {};
28
29TEST(MetricsUtilsTest, GetConnectionType) {
30 // Check that expected combinations map to the right value.
31 EXPECT_EQ(metrics::ConnectionType::kUnknown,
Sen Jiang255e22b2016-05-20 16:15:29 -070032 GetConnectionType(ConnectionType::kUnknown,
33 ConnectionTethering::kUnknown));
Colin Howesc9e98d62018-09-18 10:35:20 -070034 EXPECT_EQ(metrics::ConnectionType::kDisconnected,
35 GetConnectionType(ConnectionType::kDisconnected,
36 ConnectionTethering::kUnknown));
Alex Deymo38429cf2015-11-11 18:27:22 -080037 EXPECT_EQ(metrics::ConnectionType::kEthernet,
Sen Jiang255e22b2016-05-20 16:15:29 -070038 GetConnectionType(ConnectionType::kEthernet,
39 ConnectionTethering::kUnknown));
Amin Hassani7cc8bb02019-01-14 16:29:47 -080040 EXPECT_EQ(
41 metrics::ConnectionType::kWifi,
42 GetConnectionType(ConnectionType::kWifi, ConnectionTethering::kUnknown));
Alex Deymo38429cf2015-11-11 18:27:22 -080043 EXPECT_EQ(metrics::ConnectionType::kCellular,
Sen Jiang255e22b2016-05-20 16:15:29 -070044 GetConnectionType(ConnectionType::kCellular,
45 ConnectionTethering::kUnknown));
Alex Deymo38429cf2015-11-11 18:27:22 -080046 EXPECT_EQ(metrics::ConnectionType::kTetheredEthernet,
Sen Jiang255e22b2016-05-20 16:15:29 -070047 GetConnectionType(ConnectionType::kEthernet,
48 ConnectionTethering::kConfirmed));
Alex Deymo38429cf2015-11-11 18:27:22 -080049 EXPECT_EQ(metrics::ConnectionType::kTetheredWifi,
Sen Jiang255e22b2016-05-20 16:15:29 -070050 GetConnectionType(ConnectionType::kWifi,
51 ConnectionTethering::kConfirmed));
Alex Deymo38429cf2015-11-11 18:27:22 -080052
53 // Ensure that we don't report tethered ethernet unless it's confirmed.
54 EXPECT_EQ(metrics::ConnectionType::kEthernet,
Sen Jiang255e22b2016-05-20 16:15:29 -070055 GetConnectionType(ConnectionType::kEthernet,
56 ConnectionTethering::kNotDetected));
Alex Deymo38429cf2015-11-11 18:27:22 -080057 EXPECT_EQ(metrics::ConnectionType::kEthernet,
Sen Jiang255e22b2016-05-20 16:15:29 -070058 GetConnectionType(ConnectionType::kEthernet,
59 ConnectionTethering::kSuspected));
Alex Deymo38429cf2015-11-11 18:27:22 -080060 EXPECT_EQ(metrics::ConnectionType::kEthernet,
Sen Jiang255e22b2016-05-20 16:15:29 -070061 GetConnectionType(ConnectionType::kEthernet,
62 ConnectionTethering::kUnknown));
Alex Deymo38429cf2015-11-11 18:27:22 -080063
64 // Ditto for tethered wifi.
65 EXPECT_EQ(metrics::ConnectionType::kWifi,
Sen Jiang255e22b2016-05-20 16:15:29 -070066 GetConnectionType(ConnectionType::kWifi,
67 ConnectionTethering::kNotDetected));
Alex Deymo38429cf2015-11-11 18:27:22 -080068 EXPECT_EQ(metrics::ConnectionType::kWifi,
Sen Jiang255e22b2016-05-20 16:15:29 -070069 GetConnectionType(ConnectionType::kWifi,
70 ConnectionTethering::kSuspected));
Amin Hassani7cc8bb02019-01-14 16:29:47 -080071 EXPECT_EQ(
72 metrics::ConnectionType::kWifi,
73 GetConnectionType(ConnectionType::kWifi, ConnectionTethering::kUnknown));
Alex Deymo38429cf2015-11-11 18:27:22 -080074}
75
Alex Deymo38429cf2015-11-11 18:27:22 -080076} // namespace metrics_utils
77} // namespace chromeos_update_engine