summaryrefslogtreecommitdiff
path: root/util/pinmap/readers/csv/csv_test.go
blob: e1140ccb759c9fa470d1ff63d7d15aa54071a9ae (plain)
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
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2021 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package csv_test

import (
	"testing"

	"path/filepath"
	"reflect"

	"pinmap/pm"
	"pinmap/readers/csv"
)

const column = "B"

func TestName(t *testing.T) {
	var r csv.CSVReader
	if r.Name() != "csv" {
		t.Errorf("expected %s, got %s", "csv", r.Name())
	}
	pins, err := r.Read(column, filepath.Join("testdata", "data.csv"))
	if err != nil {
		t.Fatalf("data.csv: %v", err)
	}
	exp := &pm.Pins{
		Adc: []*pm.Pin{
			&pm.Pin{pm.ADC, "A1", "EC_ADC_1", "ENUM_ADC_1"},
		},
		I2c: []*pm.Pin{
			&pm.Pin{pm.I2C, "G7", "EC_I2C_CLK_0", "SENSOR"},
		},
		Gpio: []*pm.Pin{
			&pm.Pin{pm.Input, "D4", "EC_GPIO_1", "GPIO1"},
			&pm.Pin{pm.Output, "E5", "EC_GPIO_2", "GPIO2"},
			&pm.Pin{pm.OutputODL, "F6", "EC_GPIO_3", ""},
			&pm.Pin{pm.InputPU, "K10", "EC_GPIO_4", ""},
		},
	}
	check(t, "ADc", exp.Adc, pins.Adc)
	check(t, "I2c", exp.I2c, pins.I2c)
	check(t, "Gpio", exp.Gpio, pins.Gpio)
}

func check(t *testing.T, name string, exp, got []*pm.Pin) {
	if !reflect.DeepEqual(exp, got) {
		t.Errorf("%s - expected:", name)
		for _, p := range exp {
			t.Errorf("%v", *p)
		}
		t.Errorf("got:")
		for _, p := range got {
			t.Errorf("%v", *p)
		}
	}
}