blob: 572aec8bab1f7ab9351e11a48f7044a7cc2c3b6c [file] [log] [blame]
laszlocsomorc3f7b962020-02-06 05:02:11 -08001// 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.
14package com.google.devtools.build.lib.skyframe;
15
16import static com.google.common.truth.Truth.assertThat;
17
18import com.google.common.collect.ImmutableList;
laszlocsomorc3f7b962020-02-06 05:02:11 -080019import com.google.devtools.build.lib.skyframe.PrepareDepsOfPatternsValue.TargetPatternSequence;
Googler2d92ce72024-02-28 12:00:41 -080020import com.google.devtools.build.lib.skyframe.serialization.ObjectCodecs;
laszlocsomorc3f7b962020-02-06 05:02:11 -080021import com.google.devtools.build.lib.skyframe.serialization.testutils.SerializationTester;
janakra3652a32020-09-10 12:05:20 -070022import com.google.devtools.build.lib.vfs.PathFragment;
laszlocsomorc3f7b962020-02-06 05:02:11 -080023import org.junit.Test;
24import org.junit.runner.RunWith;
25import org.junit.runners.JUnit4;
26
janakra3652a32020-09-10 12:05:20 -070027/** Tests for serialization of {@link TargetPatternSequence}. */
laszlocsomorc3f7b962020-02-06 05:02:11 -080028@RunWith(JUnit4.class)
29public final class TargetPatternSequenceCodecTest {
30 @Test
31 public void testCodec() throws Exception {
32 new SerializationTester(
janakra3652a32020-09-10 12:05:20 -070033 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")))
laszlocsomorc3f7b962020-02-06 05:02:11 -080040 .runTests();
41 }
42
43 @Test
44 public void testPatternsOrderSignificant() throws Exception {
Googler2d92ce72024-02-28 12:00:41 -080045 ObjectCodecs codecs = new ObjectCodecs();
46 byte[] serialized1 =
47 codecs
48 .serialize(
49 TargetPatternSequence.create(
50 ImmutableList.of("uno", "dos"), PathFragment.create("tres")))
51 .toByteArray();
laszlocsomorc3f7b962020-02-06 05:02:11 -080052 assertThat(serialized1).asList().isNotEmpty();
Googler2d92ce72024-02-28 12:00:41 -080053
54 byte[] serialized2 =
55 codecs
56 .serialize(
57 TargetPatternSequence.create(
58 ImmutableList.of("dos", "uno"), PathFragment.create("tres")))
59 .toByteArray();
laszlocsomorc3f7b962020-02-06 05:02:11 -080060 assertThat(serialized2).asList().isNotEmpty();
61 assertThat(serialized1).isNotEqualTo(serialized2);
62 }
63}