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

#include <algorithm>
#include <string>
#include <vector>

#include "components/breadcrumbs/core/application_breadcrumbs_not_user_action_test.inc"
#include "testing/platform_test.h"

// Tests that kNotUserTriggeredActions array was correctly generated by
// generate_not_user_triggered_actions.py
using ApplicationBreadcrumbsNotUserActions = PlatformTest;

// Tests that kNotUserTriggeredActions array is not too big.
TEST_F(ApplicationBreadcrumbsNotUserActions, Size) {
  // There are three non-user-triggered actions in
  // `generate_not_user_triggered_actions_test_data.xml`.
  EXPECT_EQ(3U, std::size(kNotUserTriggeredActions));
}

// Tests that each string in kNotUserTriggeredActions array is within the
// expected length range.
TEST_F(ApplicationBreadcrumbsNotUserActions, StringLength) {
  for (const char* action : kNotUserTriggeredActions) {
    EXPECT_GT(strlen(action), 0U);
    // The longest action in `generate_not_user_triggered_actions_test_data.xml`
    // is 65 characters.
    EXPECT_LE(strlen(action), 65U) << " for " << action;
  }
}

// Tests that kNotUserTriggeredActions array is sorted to make the binary search
// possible.
TEST_F(ApplicationBreadcrumbsNotUserActions, Sorting) {
  // Use vector of strings, so std::is_sorted can compare strings, not pointers.
  std::vector<std::string> actions(std::begin(kNotUserTriggeredActions),
                                   std::end(kNotUserTriggeredActions));
  EXPECT_TRUE(std::is_sorted(actions.begin(), actions.end()));
}
