You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

60 lines
1.6 KiB

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