Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andreilitvin committed Aug 8, 2023
1 parent 36b97e2 commit b9ac195
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ java-jni:

java-class:
inputs/several_clusters.matter:
java/chip/devicecontroller/cluster/structs/SecondClusterFabricDescriptorStruct.kt: outputs/several_clusters/java/SecondClusterFabricDescriptorStruct.kt
java/chip/devicecontroller/ClusterWriteMapping.java: outputs/several_clusters/java/ClusterWriteMapping.java
java/chip/devicecontroller/ClusterReadMapping.java: outputs/several_clusters/java/ClusterReadMapping.java
java/chip/devicecontroller/ClusterIDMapping.java: outputs/several_clusters/java/ClusterIDMapping.java
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
*
* 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 chip.devicecontroller.cluster.structs

import chip.devicecontroller.cluster.*
import chip.tlv.AnonymousTag
import chip.tlv.ContextSpecificTag
import chip.tlv.Tag
import chip.tlv.TlvParsingException
import chip.tlv.TlvReader
import chip.tlv.TlvWriter

import java.util.Optional

class SecondClusterFabricDescriptorStruct (
val rootPublicKey: ByteArray,
val vendorID: Int,
val fabricID: Long,
val nodeID: Long,
val label: String,
val fabricIndex: Int) {
override fun toString(): String = buildString {
append("SecondClusterFabricDescriptorStruct {\n")
append("\trootPublicKey : $rootPublicKey\n")
append("\tvendorID : $vendorID\n")
append("\tfabricID : $fabricID\n")
append("\tnodeID : $nodeID\n")
append("\tlabel : $label\n")
append("\tfabricIndex : $fabricIndex\n")
append("}\n")
}

fun toTlv(tag: Tag, tlvWriter: TlvWriter) {
tlvWriter.apply {
startStructure(tag)
put(ContextSpecificTag(TAG_ROOT_PUBLIC_KEY), rootPublicKey)
put(ContextSpecificTag(TAG_VENDOR_I_D), vendorID)
put(ContextSpecificTag(TAG_FABRIC_I_D), fabricID)
put(ContextSpecificTag(TAG_NODE_I_D), nodeID)
put(ContextSpecificTag(TAG_LABEL), label)
put(ContextSpecificTag(TAG_FABRIC_INDEX), fabricIndex)
endStructure()
}
}

companion object {
private const val TAG_ROOT_PUBLIC_KEY = 1
private const val TAG_VENDOR_I_D = 2
private const val TAG_FABRIC_I_D = 3
private const val TAG_NODE_I_D = 4
private const val TAG_LABEL = 5
private const val TAG_FABRIC_INDEX = 254

fun fromTlv(tag: Tag, tlvReader: TlvReader) : SecondClusterFabricDescriptorStruct {
tlvReader.enterStructure(tag)
val rootPublicKey = tlvReader.getByteArray(ContextSpecificTag(TAG_ROOT_PUBLIC_KEY))
val vendorID = tlvReader.getInt(ContextSpecificTag(TAG_VENDOR_I_D))
val fabricID = tlvReader.getLong(ContextSpecificTag(TAG_FABRIC_I_D))
val nodeID = tlvReader.getLong(ContextSpecificTag(TAG_NODE_I_D))
val label = tlvReader.getString(ContextSpecificTag(TAG_LABEL))
val fabricIndex = tlvReader.getInt(ContextSpecificTag(TAG_FABRIC_INDEX))

tlvReader.exitContainer()

return SecondClusterFabricDescriptorStruct(rootPublicKey, vendorID, fabricID, nodeID, label, fabricIndex)
}
}
}

0 comments on commit b9ac195

Please sign in to comment.