laszlocsomor | c3f7b96 | 2020-02-06 05:02:11 -0800 | [diff] [blame] | 1 | // Copyright 2020 The Bazel Authors. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | package com.google.devtools.build.lib.skyframe; |
| 15 | |
| 16 | import static com.google.common.truth.Truth.assertThat; |
| 17 | |
| 18 | import com.google.common.collect.ImmutableList; |
laszlocsomor | c3f7b96 | 2020-02-06 05:02:11 -0800 | [diff] [blame] | 19 | import com.google.devtools.build.lib.skyframe.PrepareDepsOfPatternsValue.TargetPatternSequence; |
Googler | 2d92ce7 | 2024-02-28 12:00:41 -0800 | [diff] [blame] | 20 | import com.google.devtools.build.lib.skyframe.serialization.ObjectCodecs; |
laszlocsomor | c3f7b96 | 2020-02-06 05:02:11 -0800 | [diff] [blame] | 21 | import com.google.devtools.build.lib.skyframe.serialization.testutils.SerializationTester; |
janakr | a3652a3 | 2020-09-10 12:05:20 -0700 | [diff] [blame] | 22 | import com.google.devtools.build.lib.vfs.PathFragment; |
laszlocsomor | c3f7b96 | 2020-02-06 05:02:11 -0800 | [diff] [blame] | 23 | import org.junit.Test; |
| 24 | import org.junit.runner.RunWith; |
| 25 | import org.junit.runners.JUnit4; |
| 26 | |
janakr | a3652a3 | 2020-09-10 12:05:20 -0700 | [diff] [blame] | 27 | /** Tests for serialization of {@link TargetPatternSequence}. */ |
laszlocsomor | c3f7b96 | 2020-02-06 05:02:11 -0800 | [diff] [blame] | 28 | @RunWith(JUnit4.class) |
| 29 | public final class TargetPatternSequenceCodecTest { |
| 30 | @Test |
| 31 | public void testCodec() throws Exception { |
| 32 | new SerializationTester( |
janakr | a3652a3 | 2020-09-10 12:05:20 -0700 | [diff] [blame] | 33 | TargetPatternSequence.create(ImmutableList.of(), PathFragment.EMPTY_FRAGMENT), |
| 34 | TargetPatternSequence.create( |
| 35 | ImmutableList.of("foo", "bar"), PathFragment.create("baz")), |
| 36 | TargetPatternSequence.create( |
| 37 | ImmutableList.of("uno", "dos"), PathFragment.create("tres")), |
| 38 | TargetPatternSequence.create( |
| 39 | ImmutableList.of("dos", "uno"), PathFragment.create("tres"))) |
laszlocsomor | c3f7b96 | 2020-02-06 05:02:11 -0800 | [diff] [blame] | 40 | .runTests(); |
| 41 | } |
| 42 | |
| 43 | @Test |
| 44 | public void testPatternsOrderSignificant() throws Exception { |
Googler | 2d92ce7 | 2024-02-28 12:00:41 -0800 | [diff] [blame] | 45 | ObjectCodecs codecs = new ObjectCodecs(); |
| 46 | byte[] serialized1 = |
| 47 | codecs |
| 48 | .serialize( |
| 49 | TargetPatternSequence.create( |
| 50 | ImmutableList.of("uno", "dos"), PathFragment.create("tres"))) |
| 51 | .toByteArray(); |
laszlocsomor | c3f7b96 | 2020-02-06 05:02:11 -0800 | [diff] [blame] | 52 | assertThat(serialized1).asList().isNotEmpty(); |
Googler | 2d92ce7 | 2024-02-28 12:00:41 -0800 | [diff] [blame] | 53 | |
| 54 | byte[] serialized2 = |
| 55 | codecs |
| 56 | .serialize( |
| 57 | TargetPatternSequence.create( |
| 58 | ImmutableList.of("dos", "uno"), PathFragment.create("tres"))) |
| 59 | .toByteArray(); |
laszlocsomor | c3f7b96 | 2020-02-06 05:02:11 -0800 | [diff] [blame] | 60 | assertThat(serialized2).asList().isNotEmpty(); |
| 61 | assertThat(serialized1).isNotEqualTo(serialized2); |
| 62 | } |
| 63 | } |