Create Test code with concurrent_map
authorjw_wonny.cha <jw_wonny.cha@samsung.com>
Thu, 14 Mar 2019 07:13:47 +0000 (16:13 +0900)
committerjw_wonny.cha <jw_wonny.cha@samsung.com>
Thu, 14 Mar 2019 07:13:47 +0000 (16:13 +0900)
src/servicemgr/test/concurrent_map_test.go [new file with mode: 0644]

diff --git a/src/servicemgr/test/concurrent_map_test.go b/src/servicemgr/test/concurrent_map_test.go
new file mode 100644 (file)
index 0000000..f30da36
--- /dev/null
@@ -0,0 +1,74 @@
+package test
+
+import (
+       "servicemgr"
+       "strings"
+       "testing"
+)
+
+func TestMapSetGet(t *testing.T) {
+       servicemgr.InitServiceMap()
+       servicemgr.ServiceNameMap.Set(uint64(1), "hello")
+
+       str, _ := servicemgr.ServiceNameMap.Get(uint64(1))
+       if strings.Compare(str.(string), "hello") != 0 {
+               t.Error("Wrong Result")
+       }
+}
+
+func TestMapRemove(t *testing.T) {
+       servicemgr.InitServiceMap()
+       servicemgr.ServiceNameMap.Set(uint64(1), "hello")
+
+       servicemgr.ServiceNameMap.Remove(uint64(1))
+
+       exist, _ := servicemgr.ServiceNameMap.Get(uint64(1))
+       if exist != nil {
+               t.Error("ConcurrentMap Remove API is failed")
+       }
+}
+
+func TestMapModify(t *testing.T) {
+       servicemgr.InitServiceMap()
+       servicemgr.ServiceNameMap.Set(uint64(1), "hello")
+       servicemgr.ServiceNameMap.Set(uint64(1), "hello2")
+
+       str, _ := servicemgr.ServiceNameMap.Get(uint64(1))
+       if strings.Compare(str.(string), "hello2") != 0 {
+               t.Error("Wrong Result")
+       }
+}
+
+func TestMapIter(t *testing.T) {
+       servicemgr.InitServiceMap()
+       servicemgr.ServiceNameMap.Set(uint64(1), "hello")
+       servicemgr.ServiceNameMap.Set(uint64(2), "hello2")
+
+       mapItem := servicemgr.ServiceNameMap.Iter()
+       compareStr := make([]string, 10)
+       idx := 0
+
+       for {
+               msg := <-mapItem
+
+               t.Log(msg.Key, msg.Value)
+
+               if msg.Value == nil && msg.Key == 0 {
+                       break
+               } else {
+                       compareStr[idx] = msg.Value.(string)
+               }
+       }
+
+       for _, str := range compareStr {
+               if len(str) == 0 {
+                       break
+               }
+
+               if strings.Compare(str, "hello") == 0 || strings.Compare(str, "hello2") == 0 {
+                       continue
+               } else {
+                       t.Fail()
+               }
+       }
+}