content: /*
   * Copyright 2021 Alibaba Group Holding Limited.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *  	http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package com.alibaba.graphscope.stdcxx;
  
  import com.alibaba.fastffi.FFIByteString;
  import com.alibaba.fastffi.FFITypeFactory;
  import com.alibaba.graphscope.stdcxx.StdVector.Factory;
  
  import org.junit.Assert;
  import org.junit.Test;
  
  public class StdVectorTest {
  
      private Factory<Integer> intVectorFactory =
              FFITypeFactory.getFactory(StdVector.class, "std::vector<jint>");
  
      private StdVector.Factory<FFIByteString> stringVectorFactory =
              FFITypeFactory.getFactory(StdVector.class, "std::vector<std::string>");
      private StdString.Factory stringFactory = StdString.factory;
  
      @Test
      public void test1() {
          StdVector<Integer> integerStdVector = intVectorFactory.create();
          for (int i = 0; i < 10; ++i) {
              integerStdVector.push_back(i);
          }
          Assert.assertTrue(integerStdVector.size() == 10);
          for (int i = 0; i < 10; ++i) {
              Assert.assertEquals(i, integerStdVector.get(i).intValue());
          }
          integerStdVector.clear();
      }
  
      @Test
      public void test2() {
          StdVector<FFIByteString> stringVector = stringVectorFactory.create();
          for (int i = 0; i < 10; ++i) {
              String tmp = "tmp" + i;
              FFIByteString str = FFITypeFactory.newByteString();
              str.copyFrom(tmp);
              stringVector.push_back(str);
          }
          Assert.assertTrue(stringVector.size() == 10);
          for (int i = 0; i < 10; ++i) {
              Assert.assertEquals("tmp" + i, stringVector.get(i).toString());
          }
          stringVector.clear();
      }
  }
  