aboutsummaryrefslogtreecommitdiff
path: root/Examples/test-suite/go/cpp11_std_array_runme.go
blob: 97b5df2ec8dc739fa82d9799985d1f7a94e0fe5c (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
59
60
61
62
63
64
65
66
67
68
package main

import (
  "fmt"
  "swigtests/cpp11_std_array"
)

func CompareContainers(actual cpp11_std_array.ArrayInt6, expected [6]int) error {
  if int(actual.Size()) != len(expected) {
    return fmt.Errorf("Sizes are different: %d %d", actual.Size(), len(expected))
  }
  for i := 0; i < int(actual.Size()); i++ {
    actualValue := actual.Get(i)
    expectedValue := expected[i]
    if actualValue != expectedValue {
      return fmt.Errorf("Value is wrong for element %d. Expected %d got: %d", i, expectedValue, actualValue)
    }
  }
  if actual.IsEmpty() {
	  return fmt.Errorf("ai should not be empty")
  }
  return nil
}

func main() {
  ai := cpp11_std_array.NewArrayInt6()
  ps := [6]int{0, 0, 0, 0, 0, 0}
  CompareContainers(ai, ps)

  vals := [6]int{10, 20, 30, 40, 50, 60}
  for i := 0; i < len(vals); i++ {
    ai.Set(i, vals[i])
  }
  CompareContainers(ai, vals);

  // Check return
  vals = [6]int{-2, -1, 0, 0, 1, 2}
  CompareContainers(cpp11_std_array.ArrayOutVal(), vals);
  CompareContainers(cpp11_std_array.ArrayOutConstRef(), vals);
  CompareContainers(cpp11_std_array.ArrayOutRef(), vals);
  CompareContainers(cpp11_std_array.ArrayOutPtr(), vals);

  // Check passing arguments
  vals = [6]int{9, 8, 7, 6, 5, 4}
  valsArrayInt6 := cpp11_std_array.NewArrayInt6()
  for i := 0; i < len(vals); i++ {
    valsArrayInt6.Set(i, vals[i])
  }

  ai = cpp11_std_array.ArrayInVal(valsArrayInt6);
  CompareContainers(ai, vals);

  ai = cpp11_std_array.ArrayInConstRef(valsArrayInt6);
  CompareContainers(ai, vals);

  ai = cpp11_std_array.NewArrayInt6(valsArrayInt6);
  cpp11_std_array.ArrayInRef(ai);
  CompareContainers(ai, vals);

  ai = cpp11_std_array.NewArrayInt6(valsArrayInt6);
  cpp11_std_array.ArrayInPtr(ai);
  CompareContainers(ai, vals);

  // Fill
  ai.Fill(111)
  vals = [6]int{111, 111, 111, 111, 111, 111}
  CompareContainers(ai, vals);
}