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
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59

ash / ambient / util / ambient_util_unittest.cc [blame]

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/ambient/util/ambient_util.h"

#include <string>

#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace ash {
namespace ambient {
namespace util {
namespace {
using ::testing::Eq;
using ::testing::Lt;
using ::testing::Not;
}  // namespace

TEST(AmbientUtilTest, ParseDynamicLottieAssetId) {
  ParsedDynamicAssetId output;
  EXPECT_FALSE(ParseDynamicLottieAssetId("StaticAsset", output));
  EXPECT_FALSE(ParseDynamicLottieAssetId("_CrOS_UnknownAsset", output));
  ASSERT_TRUE(ParseDynamicLottieAssetId("_CrOS_Photo_PositionA_1", output));
  EXPECT_THAT(output.position_id, Eq("A"));
  EXPECT_THAT(output.idx, Eq(1));
  ASSERT_TRUE(ParseDynamicLottieAssetId("_CrOS_Photo_PositionB_1", output));
  EXPECT_THAT(output.position_id, Eq("B"));
  EXPECT_THAT(output.idx, Eq(1));
  ASSERT_TRUE(
      ParseDynamicLottieAssetId("_CrOS_Photo_PositionTopLeft_1", output));
  EXPECT_THAT(output.position_id, Eq("TopLeft"));
  EXPECT_THAT(output.idx, Eq(1));
  ASSERT_TRUE(
      ParseDynamicLottieAssetId("_CrOS_Photo_PositionTopRight_2", output));
  EXPECT_THAT(output.position_id, Eq("TopRight"));
  EXPECT_THAT(output.idx, Eq(2));
  ASSERT_TRUE(ParseDynamicLottieAssetId("_CrOS_Photo_PositionA_1.png", output));
  EXPECT_THAT(output.position_id, Eq("A"));
  EXPECT_THAT(output.idx, Eq(1));
}

TEST(AmbientUtilTest, CompareDynamicLottieAssetId) {
  EXPECT_THAT(ParsedDynamicAssetId({"A", 1}),
              Lt(ParsedDynamicAssetId({"A", 2})));
  EXPECT_THAT(ParsedDynamicAssetId({"A", 2}),
              Not(Lt(ParsedDynamicAssetId({"A", 1}))));
  EXPECT_THAT(ParsedDynamicAssetId({"A", 1}),
              Lt(ParsedDynamicAssetId({"B", 1})));
  EXPECT_THAT(ParsedDynamicAssetId({"B", 1}),
              Not(Lt(ParsedDynamicAssetId({"A", 1}))));
  EXPECT_THAT(ParsedDynamicAssetId({"A", 1}),
              Not(Lt(ParsedDynamicAssetId({"A", 1}))));
}

}  // namespace util
}  // namespace ambient
}  // namespace ash