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.

BigIntTest.java 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. Copyright (c) 2017 James Ahlborn
  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. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package com.healthmarketscience.jackcess.impl;
  14. import java.util.ArrayList;
  15. import java.util.Collections;
  16. import java.util.Comparator;
  17. import java.util.List;
  18. import java.util.Map;
  19. import com.healthmarketscience.jackcess.Column;
  20. import com.healthmarketscience.jackcess.Cursor;
  21. import com.healthmarketscience.jackcess.DataType;
  22. import com.healthmarketscience.jackcess.Database;
  23. import com.healthmarketscience.jackcess.Table;
  24. import junit.framework.TestCase;
  25. import static com.healthmarketscience.jackcess.TestUtil.*;
  26. import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
  27. import static com.healthmarketscience.jackcess.DatabaseBuilder.*;
  28. /**
  29. *
  30. * @author James Ahlborn
  31. */
  32. public class BigIntTest extends TestCase
  33. {
  34. public BigIntTest(String name) throws Exception {
  35. super(name);
  36. }
  37. public void testBigInt() throws Exception {
  38. for (final Database.FileFormat fileFormat : SUPPORTED_FILEFORMATS) {
  39. JetFormat format = DatabaseImpl.getFileFormatDetails(fileFormat)
  40. .getFormat();
  41. if(!format.isSupportedDataType(DataType.BIG_INT)) {
  42. continue;
  43. }
  44. Database db = create(fileFormat);
  45. Table t = newTable("Test")
  46. .addColumn(newColumn("id", DataType.LONG)
  47. .setAutoNumber(true))
  48. .addColumn(newColumn("data1", DataType.TEXT))
  49. .addColumn(newColumn("num1", DataType.BIG_INT))
  50. .addIndex(newIndex("idx").addColumns("num1"))
  51. .toTable(db);
  52. long[] vals = new long[] {
  53. 0L, -10L, 3844L, -45309590834L, 50392084913L, 65000L, -6489273L};
  54. List<Map<String, Object>> expectedTable =
  55. new ArrayList<Map<String, Object>>();
  56. int idx = 1;
  57. for(long lng : vals) {
  58. t.addRow(Column.AUTO_NUMBER, "" + lng, lng);
  59. expectedTable.add(createExpectedRow(
  60. "id", idx++,
  61. "data1", "" + lng,
  62. "num1", lng));
  63. }
  64. Collections.sort(expectedTable, (r1, r2) -> {
  65. Long l1 = (Long)r1.get("num1");
  66. Long l2 = (Long)r2.get("num1");
  67. return l1.compareTo(l2);
  68. });
  69. Cursor c = t.newCursor().setIndexByName("idx").toIndexCursor();
  70. assertCursor(expectedTable, c);
  71. db.close();
  72. }
  73. }
  74. }