test/script/basic/JDK-8020324.js

changeset 0
b1a7da25b547
child 962
ac62e33a99b0
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/script/basic/JDK-8020324.js	Wed Apr 27 01:36:41 2016 +0800
     1.3 @@ -0,0 +1,139 @@
     1.4 +/*
     1.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + * 
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + * 
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + * 
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + * 
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + */
    1.26 +
    1.27 +/**
    1.28 + * JDK-8020324: Implement Object.bindProperties(target, source) for beans
    1.29 + *
    1.30 + * @test
    1.31 + * @run
    1.32 + */
    1.33 +
    1.34 +var PropertyBind = Java.type("jdk.nashorn.test.models.PropertyBind")
    1.35 +var bean = new PropertyBind
    1.36 +
    1.37 +var obj1 = {}
    1.38 +Object.bindProperties(obj1, bean)
    1.39 +
    1.40 +printBanner("Two-way read-write instance field")
    1.41 +printEval("obj1.publicInt = 13")
    1.42 +printEval("bean.publicInt")
    1.43 +printEval("bean.publicInt = 15")
    1.44 +printEval("obj1.publicInt")
    1.45 +
    1.46 +printBanner("Read only public instance field")
    1.47 +printEval("obj1.publicFinalInt")
    1.48 +printEval("obj1.publicFinalInt = 16")
    1.49 +printEval("obj1.publicFinalInt")
    1.50 +printEval("bean.publicFinalInt")
    1.51 +
    1.52 +printBanner("Two-way read-write instance property")
    1.53 +printEval("obj1.readWrite = 17")
    1.54 +printEval("bean.readWrite")
    1.55 +printEval("bean.readWrite = 18")
    1.56 +printEval("obj1.readWrite")
    1.57 +printEval("obj1.getReadWrite()")
    1.58 +printEval("obj1.setReadWrite(19)")
    1.59 +printEval("obj1.readWrite")
    1.60 +printEval("bean.readWrite")
    1.61 +
    1.62 +printBanner("Read only instance property")
    1.63 +printEval("obj1.readOnly")
    1.64 +printEval("obj1.readOnly = 20")
    1.65 +printEval("obj1.readOnly")
    1.66 +printEval("obj1.getReadOnly()")
    1.67 +printEval("bean.getReadOnly()")
    1.68 +
    1.69 +printBanner("Write only instance property")
    1.70 +printEval("obj1.writeOnly = 21")
    1.71 +printEval("obj1.writeOnly")
    1.72 +printEval("bean.writeOnly")
    1.73 +printEval("bean.peekWriteOnly()")
    1.74 +
    1.75 +var obj2 = {}
    1.76 +Object.bindProperties(obj2, PropertyBind)
    1.77 +
    1.78 +printBanner("Two-way read-write public static field")
    1.79 +printEval("obj2.publicStaticInt = 22")
    1.80 +printEval("PropertyBind.publicStaticInt")
    1.81 +printEval("PropertyBind.publicStaticInt = 23")
    1.82 +printEval("obj2.publicStaticInt")
    1.83 +
    1.84 +printBanner("Read only public static field")
    1.85 +printEval("obj2.publicStaticFinalInt")
    1.86 +printEval("obj2.publicStaticFinalInt = 24")
    1.87 +printEval("obj2.publicStaticFinalInt")
    1.88 +printEval("PropertyBind.publicStaticFinalInt")
    1.89 +
    1.90 +printBanner("Two-way read-write static property")
    1.91 +printEval("obj2.staticReadWrite = 25")
    1.92 +printEval("PropertyBind.staticReadWrite")
    1.93 +printEval("PropertyBind.staticReadWrite = 26")
    1.94 +printEval("obj2.staticReadWrite")
    1.95 +printEval("obj2.getStaticReadWrite()")
    1.96 +printEval("obj2.setStaticReadWrite(27)")
    1.97 +printEval("obj2.staticReadWrite")
    1.98 +printEval("PropertyBind.staticReadWrite")
    1.99 +
   1.100 +printBanner("Read only static property")
   1.101 +printEval("obj2.staticReadOnly")
   1.102 +printEval("obj2.staticReadOnly = 28")
   1.103 +printEval("obj2.staticReadOnly")
   1.104 +printEval("obj2.getStaticReadOnly()")
   1.105 +printEval("PropertyBind.getStaticReadOnly()")
   1.106 +
   1.107 +printBanner("Write only static property")
   1.108 +printEval("obj2.staticWriteOnly = 29")
   1.109 +printEval("obj2.staticWriteOnly")
   1.110 +printEval("PropertyBind.staticWriteOnly")
   1.111 +printEval("PropertyBind.peekStaticWriteOnly()")
   1.112 +
   1.113 +printBanner("Sanity check to ensure property values remained what they were")
   1.114 +printEval("obj1.publicInt")
   1.115 +printEval("bean.publicInt")
   1.116 +printEval("obj1.publicFinalInt")
   1.117 +printEval("bean.publicFinalInt")
   1.118 +printEval("obj1.readWrite")
   1.119 +printEval("bean.readWrite")
   1.120 +printEval("obj1.readOnly")
   1.121 +printEval("bean.readOnly")
   1.122 +printEval("bean.peekWriteOnly()")
   1.123 +
   1.124 +printEval("obj2.publicStaticInt")
   1.125 +printEval("PropertyBind.publicStaticInt")
   1.126 +printEval("obj2.publicStaticFinalInt")
   1.127 +printEval("PropertyBind.publicStaticFinalInt")
   1.128 +printEval("obj2.staticReadWrite")
   1.129 +printEval("PropertyBind.staticReadWrite")
   1.130 +printEval("obj2.staticReadOnly")
   1.131 +printEval("PropertyBind.staticReadOnly")
   1.132 +printEval("PropertyBind.peekStaticWriteOnly()")
   1.133 +
   1.134 +
   1.135 +function printEval(s) {
   1.136 +    print(s + ": " + eval(s))
   1.137 +}
   1.138 +
   1.139 +function printBanner(s) {
   1.140 +    print()
   1.141 +    print("==== " + s + " ====")
   1.142 +}

mercurial