def ApplicationInfo(self, orig): """ :param orig: ApplicationInfo. """ parcel = Parcel() orig.writeToParcel(parcel, 0) parcel.setDataPosition(0) self.__init__() self._readFromParcel(parcel)
def PackageItemInfo(self, orig): """ :param orig: PackageItemInfo. """ self.__init__() parcel = Parcel() orig.writeToParcel(parcel, 0) parcel.setDataPosition(0) self.PackageItemInfo(parcel)
def parcel(): p = Parcel() for datatype, value in primitives: datatype = datatype.title() writemethod = 'write' + datatype writemethod = getattr(p, writemethod) writemethod(value) p.setDataPosition(0) return p
def parcelofarray(): p = Parcel() for datatype, value in primitives: datatype = datatype.title() value = 5 * [value] writemethod = 'write%sArray' % datatype writemethod = getattr(p, writemethod) writemethod(value) p.setDataPosition(0) return p
def test_PersistableBundle_iparcelable(): abundle = PersistableBundle() abundle.putBoolean('abool', True) abundle.putDouble('adouble', 2.5) p = Parcel() abundle.writeToParcel(p, 0) p.setDataPosition(0) obj = PersistableBundle(p) assert abundle.equals(obj), 'ERROR: parcelable interface'
def test_parcelable(): parcel = Parcel() cname.writeToParcel(parcel,0) parcel.setDataPosition(0) acname = ComponentName.readFromParcel(parcel) assert cname.equals(acname), 'ERROR: No correspondence between ' \ 'writeToParcel and readToParcel' npos = parcel.dataPosition() parcel.writeParcelable(cname, 0) parcel.setDataPosition(npos) fparcel = parcel.readParcelable(None) assert cname.equals(fparcel), 'ERROR: parcelable'
def _contentConverter(self, item): componentType, componentContent = item[-2], str(item[-1]) ifilterStr = bytearray(componentContent.decode('base64')) parcel = Parcel() parcel.unmarshall(ifilterStr, 0, len(ifilterStr)) parcel.setDataPosition(0) if componentType == 'intent-filter': return parcel.readTypedObject(IntentFilter.CREATOR) ifilter = {} parcel.readMap(ifilter, None) return ifilter
def test_ParcelAndUnparcel(): uri = 'android-app://com.example.app/#Intent;action=com.example.MY_ACTION;' \ 'i.some_int=100;S.some_str=hello;end' intent = Intent.Intent.parseUri(uri, Intent.URI_ANDROID_APP_SCHEME) intent.setData(Uri.parse('content://com.example.app/users/1')) p = Parcel() intent.writeToParcel(p, 0) p.setDataPosition(0) other = Intent.Intent.CREATOR.createFromParcel(p) assert intent.getAction() == other.getAction() assert intent.getData() == other.getData() assert intent.getType() == other.getType() assert intent.getFlags() == other.getFlags() assert intent.getComponent() == other.getComponent() assert intent.getSourceBounds() == other.getSourceBounds() assert intent.getCategories() == other.getCategories() assert intent.getClipData() == other.getClipData()
def test_marshallunmarshall(parcel): marshall = parcel.marshall() q = Parcel() q.unmarshall(marshall, 0, len(marshall)) q.setDataPosition(0) test_primitives(q) pass
def test_bundles(): pBundle = PersistableBundle() pBundle.putBoolean('boolean', True) pBundle.putInt('integer', 234) pBundle.putString('string', 'esta es una string') p = Parcel() p.writePersistableBundle(pBundle) p.setDataPosition(0) qBundle = p.readPersistableBundle() assert pBundle.equals(qBundle), "ERROR: read/writePersistableBundle"
def test_ReadWriteParcelable(): hopi = MyParcelable() hopi.setData(256) parcel = Parcel() parcel.writeParcelable(hopi, 0) parcel.setDataPosition(0) anazazi = parcel.readParcelable(None) assert hopi.getData() == anazazi.getData() pass
def test_classmethods(): acname = ComponentName.createRelative(pck, cname.getShortClassName()) assert cname.equals(acname), 'ERROR: createRelative' parcel = Parcel() parcel.writeString(pck) parcel.writeString(cls) parcel.setDataPosition(0) acname = ComponentName.readFromParcel(parcel) assert cname.equals(acname), 'ERROR: readFromParcel' astring = cname.flattenToShortString() acname = ComponentName.unflattenFromString(astring) assert cname.equals(acname), 'ERROR: unflattenFromString'
def test_untypedcontainers(parcel): p = Parcel() keys, values = zip(*primitives) map(lambda x: p.writeValue(x), values) p.writeArray(values) p.writeList(values) p.setDataPosition(0) q = map(lambda x: p.readValue(None), range(len(keys))) qa = p.readArray(None) ql = len(values) * [0] p.readList(ql, None) for anArray in [q, qa, ql]: for k, key in enumerate(keys): if key in ['double', 'float']: bFlag = abs(values[k] - anArray[k]) < 0.01 else: bFlag = values[k] == anArray[k] assert bFlag, 'Error read/writeArray: %s' % key aMap = dict(uno=1, dos=2.5, tres='parejas cruzadas') p = Parcel() p.writeMap(aMap) p.setDataPosition(0) q = {} p.readMap(q, None) assert aMap == q, "ERROR read/writeMap"
def test_parcelables(): strVars = ['zero', 'one', 'two', 'three'] parcelableList = map(lambda x: MyParcelable(*x), enumerate(strVars)) aparcelable = parcelableList[0] p = Parcel() p.writeTypedObject(aparcelable, 0) p.writeTypedArray(parcelableList, 0) p.writeTypedList(parcelableList) p.setDataPosition(0) q = p.readTypedObject(MyParcelable.CREATOR) qa = p.createTypedArray(MyParcelable.CREATOR) ql = p.createTypedArrayList(MyParcelable.CREATOR) assert aparcelable.equals( q), "Error TypedObject: Read and write Typed object" assert all(map(lambda x: x[0].equals(x[1]), zip(parcelableList, ql))), "ERROR createTypedArrayList" assert all(map(lambda x: x[0].equals(x[1]), zip(parcelableList, qa))), "ERROR createTypedArray" p = Parcel() p.writeParcelable(aparcelable, 0) p.writeParcelable(aparcelable, 0) p.writeParcelableArray(parcelableList, 0) p.setDataPosition(0) q = p.readParcelable(None) w = p.readParcelable('test_parcel.MyParcelable') qa = p.readParcelableArray(None) assert aparcelable.equals(q), "ERROR write/readParcelable" assert aparcelable.equals(w), "ERROR write/readParcelable" assert all(map(lambda x: x[0].equals(x[1]), zip(parcelableList, qa))), "ERROR createTypedArrayList" pass
def test_appendFrom(parcel): q = Parcel() q.appendFrom(parcel, 0, parcel.dataSize()) q.setDataPosition(0) test_primitives(q) pass