(byte type)
| 36 | |
| 37 | public class TestNull { |
| 38 | public static boolean test(byte type) throws ExecException { |
| 39 | Random r = new Random(); |
| 40 | ConstantExpression lt = (ConstantExpression)GenPhyOp.exprConst(); |
| 41 | lt.setResultType(type); |
| 42 | Tuple dummyTuple = TupleFactory.getInstance().newTuple(1); |
| 43 | lt.attachInput(dummyTuple); |
| 44 | POIsNull isNullExpr = (POIsNull)GenPhyOp.compIsNullExpr(); |
| 45 | isNullExpr.setExpr(lt); |
| 46 | isNullExpr.setOperandType(type); |
| 47 | |
| 48 | Object inp1; |
| 49 | Result res; |
| 50 | Boolean ret; |
| 51 | switch (type) { |
| 52 | case DataType.BAG: |
| 53 | inp1 = GenRandomData.genRandSmallTupDataBag(r, 10, 100); |
| 54 | res = isNullExpr.getNextBoolean(); |
| 55 | if ((Boolean)res.result != true) |
| 56 | return false; |
| 57 | lt.setValue(inp1); |
| 58 | res = isNullExpr.getNextBoolean(); |
| 59 | ret = (DataType.compare(inp1, null) == 0); |
| 60 | if (!res.result.equals(ret)) |
| 61 | return false; |
| 62 | // set the input to null and test |
| 63 | lt.setValue((DataBag)null); |
| 64 | res = isNullExpr.getNextBoolean(); |
| 65 | if (!res.result.equals(true)) |
| 66 | return false; |
| 67 | return true; |
| 68 | case DataType.BOOLEAN: |
| 69 | inp1 = r.nextBoolean(); |
| 70 | res = isNullExpr.getNextBoolean(); |
| 71 | if ((Boolean)res.result != true) |
| 72 | return false; |
| 73 | lt.setValue(inp1); |
| 74 | res = isNullExpr.getNextBoolean(); |
| 75 | ret = (DataType.compare(inp1, null) == 0); |
| 76 | if (!(res.result.equals(ret))) |
| 77 | return false; |
| 78 | // set the input to null and test |
| 79 | lt.setValue((Boolean)null); |
| 80 | res = isNullExpr.getNextBoolean(); |
| 81 | ret = (DataType.compare(inp1, null) == 0); |
| 82 | if (!(res.result.equals(true))) |
| 83 | return false; |
| 84 | return true; |
| 85 | case DataType.BYTEARRAY: |
| 86 | inp1 = GenRandomData.genRandDBA(r); |
| 87 | res = isNullExpr.getNextBoolean(); |
| 88 | if ((Boolean)res.result != true) |
| 89 | return false; |
| 90 | lt.setValue(inp1); |
| 91 | res = isNullExpr.getNextBoolean(); |
| 92 | ret = (DataType.compare(inp1, null) == 0); |
| 93 | if (!(res.result.equals(ret))) |
| 94 | return false; |
| 95 | // set the input to null and test |
no test coverage detected