diff --git a/test/BUILD.gn b/test/BUILD.gn index b33d1eb0a3a9..72e926c2efb6 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -89,6 +89,7 @@ test("brave_unit_tests") { sources += [ "//brave/vendor/bat-native-ledger/src/bat_get_media_unittest.cc", "//brave/vendor/bat-native-ledger/src/bat_helper_unittest.cc", + "//brave/vendor/bat-native-ledger/src/bat_publishers_unittest.cc", "//brave/vendor/bat-native-ledger/src/test/niceware_partial_unittest.cc", "//brave/components/brave_rewards/browser/publisher_info_database_unittest.cc", "//brave/vendor/bat-native-usermodel/test/usermodel_unittest.cc", diff --git a/vendor/bat-native-ledger/src/bat_publishers.h b/vendor/bat-native-ledger/src/bat_publishers.h index 19ce29d455cc..506772c92d8d 100644 --- a/vendor/bat-native-ledger/src/bat_publishers.h +++ b/vendor/bat-native-ledger/src/bat_publishers.h @@ -15,6 +15,7 @@ #include "bat/ledger/ledger_callback_handler.h" #include "bat/ledger/publisher_info.h" #include "bat_helper.h" +#include "base/gtest_prod_util.h" namespace bat_ledger { class LedgerImpl; @@ -26,6 +27,8 @@ struct PUBLISHER_STATE_ST; namespace braveledger_bat_publishers { +// FORWARD_DECLARE_TEST(BatPublishersTest, calcScoreConsts); + class BatPublishers : public ledger::LedgerCallbackHandler { public: @@ -132,7 +135,8 @@ class BatPublishers : public ledger::LedgerCallbackHandler { bool isVerified(const std::string& publisher_id); private: - + friend class BatPublishersTest; + FRIEND_TEST_ALL_PREFIXES(BatPublishersTest, calcScoreConsts); void onPublisherActivitySave(uint64_t windowId, const ledger::VisitData& visit_data, ledger::Result result, diff --git a/vendor/bat-native-ledger/src/bat_publishers_unittest.cc b/vendor/bat-native-ledger/src/bat_publishers_unittest.cc new file mode 100644 index 000000000000..622593875425 --- /dev/null +++ b/vendor/bat-native-ledger/src/bat_publishers_unittest.cc @@ -0,0 +1,26 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public +* License, v. 2.0. If a copy of the MPL was not distributed with this file, +* You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "bat/ledger/ledger.h" +#include "bat_publishers.h" +#include "testing/gtest/include/gtest/gtest.h" + +// npm run test -- brave_unit_tests --filter=BatPublishersTest.* + +class BatPublishersTest : public testing::Test { +}; + +TEST_F(BatPublishersTest, calcScoreConsts) { + braveledger_bat_publishers::BatPublishers* publishers = + new braveledger_bat_publishers::BatPublishers(nullptr); + + // Test 8 seconds + publishers->calcScoreConsts(8); + + ASSERT_EQ(publishers->a_, 7000); + ASSERT_EQ(publishers->a2_, 14000); + ASSERT_EQ(publishers->a4_, 28000); + ASSERT_EQ(publishers->b_, 1000); + ASSERT_EQ(publishers->b2_, 1000000); +}