Add a test for costly alerts.

Bug: 28362720
Test: netd_{unit,integration}_test pass
Change-Id: I9c46564819f5ff5123203bbfd173876725f7b079
diff --git a/server/BandwidthControllerTest.cpp b/server/BandwidthControllerTest.cpp
index 4371d00..becfe49 100644
--- a/server/BandwidthControllerTest.cpp
+++ b/server/BandwidthControllerTest.cpp
@@ -124,6 +124,14 @@
         return mBw.runIptablesAlertFwdCmd(a, b, c);
     }
 
+    int setCostlyAlert(const std::string a, int64_t b, int64_t *c) {
+        return mBw.setCostlyAlert(a, b, c);
+    }
+
+    int removeCostlyAlert(const std::string a, int64_t *b) {
+        return mBw.removeCostlyAlert(a, b);
+    }
+
     void expectUpdateQuota(uint64_t quota) {
         uintptr_t dummy;
         FILE* dummyFile = reinterpret_cast<FILE*>(&dummy);
@@ -572,6 +580,31 @@
     expectIptablesRestoreCommands(expected);
 }
 
+TEST_F(BandwidthControllerTest, CostlyAlert) {
+    const int64_t kQuota = 123456;
+    int64_t alertBytes = 0;
+
+    std::vector<std::string> expected = {
+        "-A bw_costly_shared -m quota2 ! --quota 123456 --name sharedAlert\n",
+    };
+    EXPECT_EQ(0, setCostlyAlert("shared", kQuota, &alertBytes));
+    EXPECT_EQ(kQuota, alertBytes);
+    expectIptablesCommands(expected);
+
+    expected = {};
+    expectUpdateQuota(kQuota);
+    EXPECT_EQ(0, setCostlyAlert("shared", kQuota + 1, &alertBytes));
+    EXPECT_EQ(kQuota + 1, alertBytes);
+    expectIptablesCommands(expected);
+
+    expected = {
+        "-D bw_costly_shared -m quota2 ! --quota 123457 --name sharedAlert\n"
+    };
+    EXPECT_EQ(0, removeCostlyAlert("shared", &alertBytes));
+    EXPECT_EQ(0, alertBytes);
+    expectIptablesCommands(expected);
+}
+
 TEST_F(BandwidthControllerTest, ManipulateSpecialApps) {
     std::vector<const char *> appUids = { "1000", "1001", "10012" };