github.com/westcoastroms/westcoastroms-build@v0.0.0-20190928114312-2350e5a73030/build/soong/third_party/zip/android_test.go (about)

     1  // Copyright 2017 Google Inc. 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  
    15  package zip
    16  
    17  import (
    18  	"bytes"
    19  	"testing"
    20  )
    21  
    22  var stripZip64Testcases = []struct {
    23  	name string
    24  	in   []byte
    25  	out  []byte
    26  }{
    27  	{
    28  		name: "empty",
    29  		in:   []byte{},
    30  		out:  []byte{},
    31  	},
    32  	{
    33  		name: "trailing data",
    34  		in:   []byte{1, 2, 3},
    35  		out:  []byte{1, 2, 3},
    36  	},
    37  	{
    38  		name: "valid non-zip64 extra",
    39  		in:   []byte{2, 0, 2, 0, 1, 2},
    40  		out:  []byte{2, 0, 2, 0, 1, 2},
    41  	},
    42  	{
    43  		name: "two valid non-zip64 extras",
    44  		in:   []byte{2, 0, 2, 0, 1, 2, 2, 0, 0, 0},
    45  		out:  []byte{2, 0, 2, 0, 1, 2, 2, 0, 0, 0},
    46  	},
    47  	{
    48  		name: "simple zip64 extra",
    49  		in:   []byte{1, 0, 8, 0, 1, 2, 3, 4, 5, 6, 7, 8},
    50  		out:  []byte{},
    51  	},
    52  	{
    53  		name: "zip64 extra and valid non-zip64 extra",
    54  		in:   []byte{1, 0, 8, 0, 1, 2, 3, 4, 5, 6, 7, 8, 2, 0, 0, 0},
    55  		out:  []byte{2, 0, 0, 0},
    56  	},
    57  	{
    58  		name: "invalid extra",
    59  		in:   []byte{0, 0, 8, 0, 0, 0},
    60  		out:  []byte{0, 0, 8, 0, 0, 0},
    61  	},
    62  	{
    63  		name: "zip64 extra and extended-timestamp extra and valid non-zip64 extra",
    64  		in:   []byte{1, 0, 8, 0, 1, 2, 3, 4, 5, 6, 7, 8, 85, 84, 5, 0, 1, 1, 2, 3, 4, 2, 0, 0, 0},
    65  		out:  []byte{2, 0, 0, 0},
    66  	},
    67  }
    68  
    69  func TestStripZip64Extras(t *testing.T) {
    70  	for _, testcase := range stripZip64Testcases {
    71  		got := stripExtras(testcase.in)
    72  		if !bytes.Equal(got, testcase.out) {
    73  			t.Errorf("Failed testcase %s\ninput: %v\n want: %v\n  got: %v\n", testcase.name, testcase.in, testcase.out, got)
    74  		}
    75  	}
    76  }