1// Copyright 2018 Google LLC 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 15package elf 16 17import ( 18 "fmt" 19 "testing" 20) 21 22type nameTest struct { 23 val interface{} 24 str string 25} 26 27var nameTests = []nameTest{ 28 {ELFOSABI_LINUX, "ELFOSABI_LINUX"}, 29 {ET_EXEC, "ET_EXEC"}, 30 {EM_860, "EM_860"}, 31 {SHN_LOPROC, "SHN_LOPROC"}, 32 {SHT_PROGBITS, "SHT_PROGBITS"}, 33 {SHF_MERGE + SHF_TLS, "SHF_MERGE+SHF_TLS"}, 34 {PT_LOAD, "PT_LOAD"}, 35 {PF_W + PF_R + 0x50, "PF_W+PF_R+0x50"}, 36 {DT_SYMBOLIC, "DT_SYMBOLIC"}, 37 {DF_BIND_NOW, "DF_BIND_NOW"}, 38 {NT_FPREGSET, "NT_FPREGSET"}, 39 {STB_GLOBAL, "STB_GLOBAL"}, 40 {STT_COMMON, "STT_COMMON"}, 41 {STV_HIDDEN, "STV_HIDDEN"}, 42 {R_X86_64_PC32, "R_X86_64_PC32"}, 43 {R_ALPHA_OP_PUSH, "R_ALPHA_OP_PUSH"}, 44 {R_ARM_THM_ABS5, "R_ARM_THM_ABS5"}, 45 {R_386_GOT32, "R_386_GOT32"}, 46 {R_PPC_GOT16_HI, "R_PPC_GOT16_HI"}, 47 {R_SPARC_GOT22, "R_SPARC_GOT22"}, 48 {ET_LOOS + 5, "ET_LOOS+5"}, 49 {ProgFlag(0x50), "0x50"}, 50} 51 52func TestNames(t *testing.T) { 53 for i, tt := range nameTests { 54 s := fmt.Sprint(tt.val) 55 if s != tt.str { 56 t.Errorf("#%d: Sprint(%d) = %q, want %q", i, tt.val, s, tt.str) 57 } 58 } 59} 60