summaryrefslogtreecommitdiff
path: root/net/nl80211_attribute_unittest.cc
blob: 21eaa2dda821ee319feb726441c3876fd20b1507 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright 2015 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "shill/net/nl80211_attribute.h"

#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include "shill/net/byte_string.h"

using testing::Test;

namespace shill {

class Nl80211AttributeTest : public Test {
};

TEST_F(Nl80211AttributeTest, RegInitiatorDecode) {
  Nl80211AttributeRegInitiator empty_attribute;
  EXPECT_FALSE(empty_attribute.InitFromValue(ByteString()));

  const uint8_t kU8Value = 123;
  ByteString u8_value(&kU8Value, 1);
  Nl80211AttributeRegInitiator u8_attribute;
  EXPECT_TRUE(u8_attribute.InitFromValue(u8_value));
  uint32_t value_from_u8_attribute;
  EXPECT_TRUE(u8_attribute.GetU32Value(&value_from_u8_attribute));
  EXPECT_EQ(kU8Value, value_from_u8_attribute);

  const uint32_t kU32Value = 123456790U;
  ByteString u32_value = ByteString::CreateFromCPUUInt32(kU32Value);
  Nl80211AttributeRegInitiator u32_attribute;
  EXPECT_TRUE(u32_attribute.InitFromValue(u32_value));
  uint32_t value_from_u32_attribute;
  EXPECT_TRUE(u32_attribute.GetU32Value(&value_from_u32_attribute));
  EXPECT_EQ(kU32Value, value_from_u32_attribute);
}

}  // namespace shill