• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 package org.chromium.net;
6 
7 import static org.junit.Assert.assertEquals;
8 
9 import org.junit.Test;
10 import org.junit.runner.RunWith;
11 
12 import org.chromium.base.test.BaseRobolectricTestRunner;
13 
14 /** Tests calculating the hash for Network Traffic Annotations. */
15 @RunWith(BaseRobolectricTestRunner.class)
16 public class NetworkTrafficAnnotationTagTest {
17     @Test
testIterativeHash()18     public void testIterativeHash() throws Exception {
19         // Reference values obtained from
20         // tools/traffic_annotation/scripts/auditor/auditor_tests.py.
21         assertEquals(3556498, NetworkTrafficAnnotationTag.iterativeHash("test"));
22         assertEquals(10236504, NetworkTrafficAnnotationTag.iterativeHash("unique_id"));
23         assertEquals(70581310, NetworkTrafficAnnotationTag.iterativeHash("123_id"));
24         assertEquals(69491511, NetworkTrafficAnnotationTag.iterativeHash("ID123"));
25         assertEquals(
26                 98652091,
27                 NetworkTrafficAnnotationTag.iterativeHash(
28                         "a_unique_"
29                                 + "looooooooooooooooooooooooooooooooooooooooooooooooooooooong_id"));
30         assertEquals(124751853, NetworkTrafficAnnotationTag.iterativeHash("bébé"));
31     }
32 }
33