File: upgrade_test.go

package info (click to toggle)
golang-golang-x-exp 0.0~git20230522.2e198f4-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 6,404 kB
  • sloc: ansic: 1,900; objc: 276; sh: 272; asm: 48; makefile: 26
file content (47 lines) | stat: -rw-r--r-- 1,525 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package iconvg

import (
	"os"
	"path/filepath"
	"testing"
)

func TestUpgradeToFileFormatVersion1(t *testing.T) {
	for _, tc := range testdataTestCases {
		original, err := os.ReadFile(filepath.FromSlash(tc.filename) + ".ivg")
		if err != nil {
			t.Errorf("%s: ReadFile: %v", tc.filename, err)
			continue
		}

		upgraded, err := UpgradeToFileFormatVersion1(original, nil)
		if err != nil {
			t.Errorf("%s: Upgrade: %v", tc.filename, err)
			continue
		}

		// For most of the testdataTestCases, we just check (above) that
		// calling UpgradeToFileFormatVersion1 returns a nil error. As a
		// further basic consistency check, we hard-code the expected results
		// for upgrading the "action-info.lores" icon.
		//
		// These 36 bytes (and its disassembly via the cmd/iconvg-disassemble
		// tool) is also a file in the test/data directory of the
		// github.com/google/iconvg repository (the repository that is
		// generally responsible for "File Format Version 1").
		if tc.filename == "testdata/action-info.lores" {
			const want = "" +
				"\x8A\x49\x56\x47\x03\x0B\x11\x51\x51\xB1\xB1\x35\x81\x59\x33\x59" +
				"\x81\x81\xA9\x35\x85\x95\x34\x7D\x95\x7D\x7D\x35\x85\x75\x34\x7D" +
				"\x75\x7D\x6D\x88"
			if got := string(upgraded); got != want {
				t.Errorf("%s: Upgrade: got:\n% 02x\nwant:\n% 02x", tc.filename, got, want)
				continue
			}
		}
	}
}